Skip to content

Commit e02000c

Browse files
committed
Taken into account PR review comments
1 parent ca13d70 commit e02000c

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

org.restlet.java/org.restlet/src/main/java/org/restlet/data/Reference.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*

org.restlet.java/org.restlet/src/test/java/org/restlet/data/ReferenceTestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ class TestFailures {
681681
"https://[normal.com@]vulndetector.com/",
682682
"https://normal.com[user@vulndetector].com/",
683683
"https://normal.com[@]vulndetector.com/",
684+
"https://user:pwd@a[1:2:3:4]/",
684685
"https://[1:2:3:4:5:6:7:8:9]",
685686
"https://[1::1::1]",
686687
"https://[1:2:3:]",

0 commit comments

Comments
 (0)