Normalize 2+ '/' in path in UriComponentsBuilder
Issue: SPR-12398
This commit is contained in:
parent
e9f53c6ddf
commit
d8941ca098
|
|
@ -720,7 +720,14 @@ public class UriComponentsBuilder {
|
|||
if (this.path.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
String path = this.path.toString().replace("//", "/");
|
||||
String path = this.path.toString();
|
||||
while (true) {
|
||||
int index = path.indexOf("//");
|
||||
if (index == -1) {
|
||||
break;
|
||||
}
|
||||
path = path.substring(0, index) + path.substring(index + 1);
|
||||
}
|
||||
return new HierarchicalUriComponents.FullPathComponent(path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -291,6 +291,14 @@ public class UriComponentsBuilderTests {
|
|||
assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments());
|
||||
}
|
||||
|
||||
// SPR-12398
|
||||
|
||||
@Test
|
||||
public void pathWithDuplicateSlashes() throws URISyntaxException {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build();
|
||||
assertEquals("/foo/bar", uriComponents.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replacePath() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://www.ietf.org/rfc/rfc2396.txt");
|
||||
|
|
|
|||
Loading…
Reference in New Issue