Ignore an empty port

Closes gh-37117
This commit is contained in:
rstoyanchev
2026-08-07 10:31:29 +03:00
parent 70ca103b22
commit 11bb7b54e5
5 changed files with 25 additions and 12 deletions
@@ -937,11 +937,17 @@ class UriComponentsBuilderTests {
@ParameterizedTest
@EnumSource
void verifyInvalidPort(ParserType parserType) {
String url = "http://localhost:XXX/path";
assertThatIllegalArgumentException()
.isThrownBy(() -> UriComponentsBuilder.fromUriString(url, parserType).build().toUri());
assertThatIllegalArgumentException()
.isThrownBy(() -> UriComponentsBuilder.fromUriString(url, parserType).build().toUri());
assertThatIllegalArgumentException().isThrownBy(() ->
UriComponentsBuilder.fromUriString("http://localhost:XXX/path", parserType).build().toUri());
}
@ParameterizedTest // gh-37117
@EnumSource
void verifyEmptyPort(ParserType parserType) {
URI uri = UriComponentsBuilder.fromUriString("http://localhost:/path", parserType).build().toUri();
assertThat(uri.getHost()).isEqualTo("localhost");
assertThat(uri.getPort()).isEqualTo(-1);
assertThat(uri.getPath()).isEqualTo("/path");
}
@ParameterizedTest // gh-27039
@@ -201,10 +201,9 @@ class UriComponentsTests {
.isThrownBy(() -> fromUriString("https://example.com:XXX/bar", parserType));
}
@ParameterizedTest
@EnumSource
void invalidPortSet(ParserType parserType) {
UriComponents uriComponents = fromUriString("https://example.com/bar", parserType).port("XXX").build();
@Test
void invalidPortSet() {
UriComponents uriComponents = fromUriString("https://example.com/bar").port("XXX").build();
assertThatIllegalStateException()
.isThrownBy(uriComponents::getPort)
@@ -215,6 +214,12 @@ class UriComponentsTests {
.withMessage("The port must be an integer: XXX");
}
@Test // gh-37117
void emptyPortSet() {
UriComponents uriComponents = fromUriString("https://example.com/bar").port("").build();
assertThat(uriComponents.getPort()).isEqualTo(-1);
}
@Test
void expandEncoded() {
assertThatIllegalStateException().isThrownBy(() ->