Browse Source

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
pull/26928/head
Rossen Stoyanchev 5 years ago
parent
commit
0468ef46ac
  1. 2
      spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
  2. 14
      spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

2
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

@ -85,7 +85,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { @@ -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 = "([^?#]*)";

14
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

@ -1273,6 +1273,20 @@ class UriComponentsBuilderTests { @@ -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() {

Loading…
Cancel
Save