#1727 - Prevent premature base encoding in UriTemplate if host is templated.
This commit is contained in:
@@ -357,10 +357,14 @@ public class UriTemplate implements Iterable<TemplateVariable>, Serializable {
|
||||
|
||||
String head = index == -1 ? template : template.substring(0, index);
|
||||
String tail = index == -1 ? "" : template.substring(index);
|
||||
String encodedBase = UriComponentsBuilder.fromUriString(head)
|
||||
.encode()
|
||||
.build()
|
||||
.toUriString();
|
||||
|
||||
// Encode head if it's more than just the scheme
|
||||
String encodedBase = head.endsWith("://") && tail.startsWith("{")
|
||||
? head
|
||||
: UriComponentsBuilder.fromUriString(head)
|
||||
.encode()
|
||||
.build()
|
||||
.toUriString();
|
||||
|
||||
head = encodedBase.length() > head.length() ? encodedBase : head;
|
||||
|
||||
|
||||
@@ -375,6 +375,13 @@ class UriTemplateUnitTest {
|
||||
assertThat(template.toString()).isEqualTo("/path/{bar}/foo.zip?type=foo{&foobar}");
|
||||
}
|
||||
|
||||
@Test // #1727
|
||||
void supportsVariableInHostName() {
|
||||
|
||||
assertThatCode(() -> UriTemplate.of("https://{somehost}/somepath"))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
private static void assertVariables(UriTemplate template, TemplateVariable... variables) {
|
||||
assertVariables(template, Arrays.asList(variables));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user