Closed
Description
Daniel Gredler opened SPR-10270 and commented
The following code is generating empty segments for me sometimes:
ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/files/abc/xyz.xml").buildAndExpand(id).toString()
Example output:
http://localhost:8787/misc/rest/v1/manifestsessions//1/files/abc/xyz.xml
The same seems to occur for the vanilla UriComponentsBuilder. These tests fail:
@Test
public void test() throws Exception {
String uri = UriComponentsBuilder.fromUriString("http://www.foo.com/abc/").path("/x/y/z").build().toString();
assertEquals("http://www.foo.com/abc/x/y/z", uri);
}
@Test
public void test2() throws Exception {
String uri = UriComponentsBuilder.fromUriString("http://www.foo.com/abc/").pathSegment("x", "y", "z").build().toString();
assertEquals("http://www.foo.com/abc/x/y/z", uri);
}
I think the URI builders should sanitize the URLs and never return empty segments. A similar issue was addressed in #13715, except it seems that the issue was addressed only as it relates to the parameters passed to the pathSegment() method.
Affects: 3.2 GA
Issue Links:
- URIComponentsBuilder shares state across calls of .build() [SPR-11885] #16504 URIComponentsBuilder shares state across calls of .build()
Referenced from: commits 6e5cb7f