apache/dubbo

[Bug] NetUtils.matchIpExpression(String, String) fails to parse normal IPv4 address with port

已關閉

#16,308 建立於 2026年6月3日

 (0 則留言) (0 個反應) (0 位負責人)Java (26,453 個分叉)batch import
good first issuetype/bug

倉庫指標

星標
 (41,524 顆星)
PR 合併指標
 (平均合併 7天 14小時) (30 天內合併 20 個 PR)

描述

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo 3.3.7 , OpenJDK 17 , Ubuntu

Steps to reproduce this issue

  1. Add the following test case to dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java:
@Test
void testMatchIpExpressionWithIpv4AddressAndPort() throws UnknownHostException {
    assertTrue(NetUtils.matchIpExpression("*.*.*.*:90", "192.168.1.63:90"));
    assertTrue(NetUtils.matchIpExpression("192.168.1.*:90", "192.168.1.63:90"));
    assertFalse(NetUtils.matchIpExpression("192.168.1.*:80", "192.168.1.63:90"));
}
  1. Run the test:
./mvnw -pl dubbo-common -Dtest=NetUtilsTest#testMatchIpExpressionWithIpv4AddressAndPort test
  1. The test fails because 192.168.1.63:90 is treated as the host instead of being parsed into host 192.168.1.63 and port 90.
./mvnw -pl dubbo-common -Dtest=NetUtilsTest#testMatchIpExpressionWithIpv4AddressAndPort test

What you expected to happen

NetUtils.matchIpExpression(String pattern, String address) should correctly parse a normal IPv4 address with port, such as 192.168.1.63:90, into host 192.168.1.63 and port 90.

For example:

  • NetUtils.matchIpExpression("*.*.*.*:90", "192.168.1.63:90") should return true.
  • NetUtils.matchIpExpression("192.168.1.*:90", "192.168.1.63:90") should return true.
  • NetUtils.matchIpExpression("192.168.1.*:80", "192.168.1.63:90") should return false.

Anything else

This appears to be a small parsing bug in NetUtils.matchIpExpression(String, String). The fix should avoid affecting IPv6 addresses, because IPv6 addresses also contain colons.

Do you have a (mini) reproduction demo?

  • Yes, I have a minimal reproduction demo to help resolve this issue more effectively!

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

貢獻者指南