Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public static boolean matchIpExpression(String pattern, String address) throws U
String host = address;
int port = 0;
// only works for ipv4 address with 'ip:port' format
if (address.endsWith(":")) {
if (address.contains(":")) {
String[] hostPort = address.split(":");
host = hostPort[0];
port = StringUtils.parseInteger(hostPort[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@ void testMatchIpMatch() throws UnknownHostException {
assertTrue(NetUtils.matchIpExpression("192.168.1.192/26", "192.168.1.199", 90));
}

@Test
void testMatchIpExpressionDeprecatedTwoArgsWithIpPort() throws UnknownHostException {
// The deprecated 2-arg matchIpExpression should correctly parse host and port from
// an "ip:port" address string. Normal addresses like "192.168.1.63:90" should
// split into host="192.168.1.63" and port=90.
// With contains(":") this works; with endsWith(":") it does not.

// Pattern with port: host must match AND port must match
assertTrue(NetUtils.matchIpExpression("192.168.1.63:90", "192.168.1.63:90"));
assertFalse(NetUtils.matchIpExpression("192.168.1.63:90", "192.168.1.63:80"));

// Pattern without port: only host must match
assertTrue(NetUtils.matchIpExpression("192.168.1.*", "192.168.1.63:90"));
assertTrue(NetUtils.matchIpExpression("192.168.1.192/26", "192.168.1.199:8080"));
}

@Test
void testMatchIpv6WithIpPort() throws UnknownHostException {
assertTrue(NetUtils.matchIpRange("[234e:0:4567::3d:ee]", "234e:0:4567::3d:ee", 8090));
Expand Down
Loading