Skip to content

Commit

Permalink
Revisit fix for spring-projectsgh-26905 in UriComponentsBuilder
Browse files Browse the repository at this point in the history
This commit revisits the recently updated `PORT_PATTERN` in
`UriComponentsBuilder`. The fix introduced in spring-projectsgh-26905 fails with
ambiguous URL patterns, especially when the port and path parts of the
pattern are hard to differentiate, for example
"https://localhost:{port}{path}".

This commit reinstates the previous behavior without undoing the actual
fix. The only limitation introduced here is the fact that only a single
pattern variable is allowed for the port pattern part.

Fixes spring-projectsgh-27039
  • Loading branch information
bclozel authored and lxbzmy committed Mar 26, 2022
1 parent 8b83b3e commit 62a026a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {

private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")";

private static final String PORT_PATTERN = "([^/?#]*)";
private static final String PORT_PATTERN = "(\\{[^}]+}?|[^/?#]*)";

private static final String PATH_PATTERN = "([^?#]*)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,4 +1297,14 @@ void verifyInvalidPort() {
.isInstanceOf(NumberFormatException.class);
}

@Test // gh-27039
void expandPortAndPathWithoutSeparator() {
URI uri = UriComponentsBuilder
.fromUriString("ws://localhost:{port}{path}")
.buildAndExpand(7777, "/test")
.toUri();
assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test");
}


}

0 comments on commit 62a026a

Please sign in to comment.