@@ -2879,17 +2879,19 @@ private void validateAuthority(String authority) {
28792879 }
28802880 } else if (ipV6StartIndex == 0 ) {
28812881 int ipV6EndIndex = authority .indexOf (']' );
2882+
28822883 if (ipV6EndIndex == -1 ) {
28832884 throw new IllegalArgumentException ("Invalid IPv6 address format: no closing bracket" );
2884- } else {
2885- validateIpV6 (authority .substring (0 , ipV6EndIndex + 1 ));
2886- if (ipV6EndIndex + 1 < authority .length ()) {
2887- if (authority .charAt (ipV6EndIndex + 1 ) == ':' ) {
2888- validateHostPort (authority .substring (ipV6EndIndex + 2 ));
2889- } else {
2890- throw new IllegalArgumentException (
2891- "Invalid authority format: unexpected character after closing bracket" );
2892- }
2885+ }
2886+
2887+ validateIpV6 (authority .substring (1 , ipV6EndIndex )); // trim brackets
2888+
2889+ if (ipV6EndIndex + 1 < authority .length ()) {
2890+ if (authority .charAt (ipV6EndIndex + 1 ) == ':' ) {
2891+ validateHostPort (authority .substring (ipV6EndIndex + 2 ));
2892+ } else {
2893+ throw new IllegalArgumentException (
2894+ "Invalid authority format: unexpected character after closing bracket" );
28932895 }
28942896 }
28952897 } else {
@@ -2923,8 +2925,6 @@ private void validateIpV6(String ipV6) {
29232925 throw new IllegalArgumentException ("Invalid IPv6 address" );
29242926 }
29252927
2926- ipV6 = trimIpV6Brackets (ipV6 );
2927-
29282928 // Check for double colon compression (only one allowed)
29292929 int doubleColonCount = 0 ;
29302930 int idx = ipV6 .indexOf ("::" );
@@ -2967,16 +2967,6 @@ private void validateIpV6Part(final String part, final int doubleColonCount) {
29672967 }
29682968 }
29692969
2970- private String trimIpV6Brackets (String ipV6 ) {
2971- if (ipV6 .startsWith ("[" )) {
2972- ipV6 = ipV6 .substring (1 );
2973- }
2974- if (ipV6 .endsWith ("]" )) {
2975- ipV6 = ipV6 .substring (0 , ipV6 .length () - 1 );
2976- }
2977- return ipV6 ;
2978- }
2979-
29802970 /**
29812971 * Validate a scheme according to RFC 3986.
29822972 *
0 commit comments