Skip to content

fix: reject a leading plus in IPv4 octets - #1077

Open
kevin9327 wants to merge 1 commit into
TheAlgorithms:masterfrom
kevin9327:fix-ipv4-leading-plus
Open

kevin9327 wants to merge 1 commit into
TheAlgorithms:masterfrom
kevin9327:fix-ipv4-leading-plus

Conversation

@kevin9327

Copy link
Copy Markdown

What

Reject IPv4 octets that are not decimal digits, including values with a leading +.

Why

u32::from_str accepts "+1" as 1, so ipv4_to_decimal("192.168.0.+1") and alt_ipv4_to_decimal returned a successful result for an address that is not valid IPv4.

Tests

Added cases for a leading + on both conversion functions.

Rust's integer parser accepts "+1" as 1, so ipv4_to_decimal and
alt_ipv4_to_decimal treated 192.168.0.+1 as a valid address. Require
each octet to be decimal digits only and add regression tests.
@kevin9327
kevin9327 requested a review from imp2002 as a code owner November 12, 2026 02:51
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.87%. Comparing base (fed66cb) to head (81a1f34).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1077      +/-   ##
==========================================
- Coverage   95.89%   95.87%   -0.02%     
==========================================
  Files         396      396              
  Lines       30441    30451      +10     
==========================================
+ Hits        29192    29196       +4     
- Misses       1249     1255       +6     

☔ 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.

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.

2 participants