Skip to content

Commit 01e00da

Browse files
ahus1vietj
authored andcommitted
Fixing offset calculation for reg-name parsing
Closes #5926
1 parent c007600 commit 01e00da

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

vertx-core/src/main/java/io/vertx/core/net/impl/UriParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static int parseRegName(String s, int from, int to) {
6464
char c = s.charAt(from);
6565
if (isUnreserved(c) || isSubDelims(c)) {
6666
from++;
67-
} else if (c == '%' && (from + 2) < to && isHEXDIG(s.charAt(c + 1)) && isHEXDIG(s.charAt(c + 2))) {
67+
} else if (c == '%' && (from + 2) < to && isHEXDIG(s.charAt(from + 1)) && isHEXDIG(s.charAt(from + 2))) {
6868
from += 3;
6969
} else {
7070
break;

vertx-core/src/test/java/io/vertx/tests/net/HostAndPortTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ public void testParseHostAndPort() {
189189
assertHostAndPort("127.0.0.1", 8080, "127.0.0.1:8080");
190190
assertHostAndPort("example.com", 8080, "example.com:8080");
191191
assertHostAndPort("example.com", -1, "example.com");
192+
assertHostAndPort("host%3F", -1, "host%3F");
193+
assertHostAndPort("host%3F", 8080, "host%3F:8080");
192194
assertHostAndPort("0.1.2.3", -1, "0.1.2.3");
193195
assertHostAndPort("[0::]", -1, "[0::]");
194196
assertHostAndPort("", -1, "");
@@ -212,6 +214,10 @@ public void testParseInvalid() {
212214
assertFalse(HostAndPortImpl.isValidAuthority("^"));
213215
assertNull(HostAndPortImpl.parseAuthority("bücher.de", -1));
214216
assertFalse(HostAndPortImpl.isValidAuthority("bücher.de"));
217+
assertNull(HostAndPortImpl.parseAuthority("host%3", -1));
218+
assertFalse(HostAndPortImpl.isValidAuthority("host%3"));
219+
assertNull(HostAndPortImpl.parseAuthority("host%3:8080", -1));
220+
assertFalse(HostAndPortImpl.isValidAuthority("host%3:8080"));
215221
}
216222

217223
private void assertHostAndPort(String expectedHost, int expectedPort, String actual) {

0 commit comments

Comments
 (0)