Protect against '//' in UriComponentsBuilder
Refactor UriComponentsBuilder to ensure that paths do not contain empty
segments.
For example, prior to this commit:
fromUriString("http://example.com/abc/").path("/x/y/z")
would build the URL "http://example.com/abc//x/y/z" where as it will
now build "http://example.com/abc/x/y/z".
Issue: SPR-10270
This commit is contained in:
@@ -346,4 +346,12 @@ public class UriComponentsBuilderTests {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUriString(), equalTo("http://example.com/foo/../bar"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com").path("foo/../bar").build().toUri().getPath(), equalTo("/foo/../bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySegments() throws Exception {
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x", "y", "z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").path("/x/").path("/y/z").build().toString(), equalTo("http://example.com/abc/x/y/z"));
|
||||
assertThat(UriComponentsBuilder.fromUriString("http://example.com/abc/").pathSegment("x").path("y").build().toString(), equalTo("http://example.com/abc/x/y"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user