Skip to content

Fix NetUtils.matchIpExpression to correctly parse IPv4 address with port#16310

Closed
Ayasaz wants to merge 2 commits into
apache:3.3from
Ayasaz:fix/16308-netus-ipv4-port-parsing
Closed

Fix NetUtils.matchIpExpression to correctly parse IPv4 address with port#16310
Ayasaz wants to merge 2 commits into
apache:3.3from
Ayasaz:fix/16308-netus-ipv4-port-parsing

Conversation

@Ayasaz
Copy link
Copy Markdown

@Ayasaz Ayasaz commented Jun 5, 2026

What is the purpose of the change

Fix NetUtils.matchIpExpression(String pattern, String address) to correctly parse IPv4 addresses with port (e.g. 192.168.1.63:90).

Previously the method used address.endsWith(":") to detect the ip:port format, which would never match a valid IPv4 address with port since the colon is in the middle, not at the end.

Brief changelog

  • Changed the host/port parsing logic to use the existing isValidAddress() method (which matches ADDRESS_PATTERN regex ^\d{1,3}(\.\d{1,3}){3}\:\d{1,5}$) to detect IPv4 addresses with port
  • Added test case testMatchIpExpressionWithIpv4AddressAndPort covering wildcard, subnet, and port-mismatch scenarios

Verifying this change

  • Added unit test that covers:
    • Wildcard pattern with port: *.*.*.*:90 matching 192.168.1.63:90
    • Subnet pattern with port: 192.168.1.*:90 matching 192.168.1.63:90
    • Port mismatch: 192.168.1.*:80 not matching 192.168.1.63:90

Fixes #16308

The method previously used 'address.endsWith(":")' to detect 'ip:port'
format, which would never match a valid IPv4 address with port (e.g.
'192.168.1.63:90').

Changed to use the existing isValidAddress() method which already
matches the ADDRESS_PATTERN regex '^\d{1,3}(\.\d{1,3}){3}\:\d{1,5}$',
thus correctly detecting IPv4 addresses with port numbers.

Fixes apache#16308
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.80%. Comparing base (ee9c190) to head (cccbadb).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16310      +/-   ##
============================================
+ Coverage     60.77%   60.80%   +0.02%     
+ Complexity    11768       15   -11753     
============================================
  Files          1953     1953              
  Lines         89196    89196              
  Branches      13457    13457              
============================================
+ Hits          54212    54233      +21     
+ Misses        29418    29390      -28     
- Partials       5566     5573       +7     
Flag Coverage Δ
integration-tests-java21 32.11% <0.00%> (+<0.01%) ⬆️
integration-tests-java8 32.22% <0.00%> (-0.04%) ⬇️
samples-tests-java21 32.16% <0.00%> (-0.02%) ⬇️
samples-tests-java8 29.75% <0.00%> (-0.11%) ⬇️
unit-tests-java11 59.04% <100.00%> (-0.01%) ⬇️
unit-tests-java17 58.51% <100.00%> (+<0.01%) ⬆️
unit-tests-java21 58.50% <100.00%> (+0.01%) ⬆️
unit-tests-java25 58.48% <100.00%> (+0.07%) ⬆️
unit-tests-java8 59.07% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Ayasaz Ayasaz closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants