Skip to content

Commit

Permalink
Merge pull request #4948 from tsegismont/issue-4947
Browse files Browse the repository at this point in the history
HostAndPort fails to parse a nip host
  • Loading branch information
cescoffier authored Nov 15, 2023
2 parents b6d71e6 + 253254c commit 3dba400
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/net/impl/HostAndPortImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int parseIPv4Address(String s, int from, int to) {
return -1;
}
}
return from;
return from < to && s.charAt(from + 1) != ':' ? -1 : from;
}

static int parseDecOctet(String s, int from, int to) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/vertx/core/net/impl/HostAndPortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void testParseIPV4Address() {
assertEquals(7, HostAndPortImpl.parseIPv4Address("0.0.0.0", 0, 7));
assertEquals(11, HostAndPortImpl.parseIPv4Address("192.168.0.0", 0, 11));
assertEquals(-1, HostAndPortImpl.parseIPv4Address("011.168.0.0", 0, 11));
assertEquals(-1, HostAndPortImpl.parseIPv4Address("10.0.0.1.nip.io", 0, 15));
assertEquals(8, HostAndPortImpl.parseIPv4Address("10.0.0.1.nip.io", 0, 8));
}

@Test
Expand All @@ -42,17 +44,22 @@ public void testParseRegName() {
assertEquals(5, HostAndPortImpl.parseRegName("abcdef:1234", 0, 5));
assertEquals(11, HostAndPortImpl.parseRegName("example.com", 0, 11));
assertEquals(14, HostAndPortImpl.parseRegName("example-fr.com", 0, 14));
assertEquals(15, HostAndPortImpl.parseRegName("10.0.0.1.nip.io", 0, 15));
}

@Test
public void testParseHost() {
assertEquals(14, HostAndPortImpl.parseHost("example-fr.com", 0, 14));
assertEquals(5, HostAndPortImpl.parseHost("[0::]", 0, 5));
assertEquals(7, HostAndPortImpl.parseHost("0.0.0.0", 0, 7));
assertEquals(8, HostAndPortImpl.parseHost("10.0.0.1.nip.io", 0, 8));
assertEquals(15, HostAndPortImpl.parseHost("10.0.0.1.nip.io", 0, 15));
}

@Test
public void testParseHostAndPort() {
assertHostAndPort("10.0.0.1.nip.io", -1, "10.0.0.1.nip.io");
assertHostAndPort("10.0.0.1.nip.io", 8443, "10.0.0.1.nip.io:8443");
assertHostAndPort("example.com", 8080, "example.com:8080");
assertHostAndPort("example.com", -1, "example.com");
assertHostAndPort("0.1.2.3", -1, "0.1.2.3");
Expand Down

0 comments on commit 3dba400

Please sign in to comment.