RfcParser rejects invalid IPv6 host

Closes gh-36787
This commit is contained in:
rstoyanchev
2026-05-11 15:02:55 +01:00
committed by Brian Clozel
parent 224e647e1b
commit ce90e4b11f
2 changed files with 10 additions and 3 deletions
@@ -241,12 +241,16 @@ abstract class RfcUriParser {
parser.index(++i);
parser.captureHost();
if (parser.hasNext()) {
if (parser.charAtIndex() == ':') {
char next = parser.charAtIndex();
if (next == ':') {
parser.advanceTo(PORT, i + 1);
}
else {
else if (next == '/') {
parser.advanceTo(PATH, i);
}
else {
fail(parser, "Bad authority");
}
}
break;
case ':':
@@ -267,7 +267,10 @@ class UriComponentsBuilderTests {
@EnumSource
void fromUriStringInvalidIPv6Host(ParserType parserType) {
assertThatIllegalArgumentException().isThrownBy(() ->
UriComponentsBuilder.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType));
UriComponentsBuilder.fromUriString("https://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType));
assertThatIllegalArgumentException().isThrownBy(() ->
UriComponentsBuilder.fromUriString("https://[1abc:2abc:3abc::5ABC:6abc]resource", parserType));
}
@ParameterizedTest // see SPR-11970