提交 e35fe33b 编写于 作者: B Brian Clozel

Revisit fix for gh-26905 in UriComponentsBuilder

This commit revisits the recently updated `PORT_PATTERN` in
`UriComponentsBuilder`. The fix introduced in gh-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 gh-27039
上级 23f396a2
......@@ -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 = "([^?#]*)";
......
......@@ -1297,4 +1297,14 @@ class UriComponentsBuilderTests {
.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");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册