Skip to content

UriComponentsBuilder and ServletUriComponentsBuilder generate URLs with empty segments [SPR-10270] #14904

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 6e5cb7f

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions