Follow-up fix for recent change to PORT_PATTERN

The pattern was changed in 65797d04f2
to check for characters up until "/", instead of for digits, but now
also checks up until "?" and "#".

Closes gh-26905
This commit is contained in:
Rossen Stoyanchev 2021-05-10 07:18:50 +01:00
parent eb03144e9d
commit 0468ef46ac
2 changed files with 15 additions and 1 deletions

View File

@ -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 = "([^?#]*)";

View File

@ -1273,6 +1273,20 @@ class UriComponentsBuilderTests {
assertThat(path).isEqualTo("/home/path");
}
@Test
void validPort() {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567/path").build();
assertThat(uriComponents.getPort()).isEqualTo(52567);
assertThat(uriComponents.getPath()).isEqualTo("/path");
uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567?trace=false").build();
assertThat(uriComponents.getPort()).isEqualTo(52567);
assertThat(uriComponents.getQuery()).isEqualTo("trace=false");
uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567#fragment").build();
assertThat(uriComponents.getPort()).isEqualTo(52567);
assertThat(uriComponents.getFragment()).isEqualTo("fragment");
}
@Test
void verifyInvalidPort() {