Skip to content

Test IPv4 private-range boundaries for 172.16.0.0/12 - #588

Open
eomao wants to merge 1 commit into
python-validators:masterfrom
eomao:test/ipv4-private-172-boundaries
Open

eomao wants to merge 1 commit into
python-validators:masterfrom
eomao:test/ipv4-private-172-boundaries

Conversation

@eomao

@eomao eomao commented Nov 21, 2026

Copy link
Copy Markdown

Related to #564.

I could not reproduce the reported classification bug on master at 22786cc. This test-only change covers both endpoints of 172.16.0.0/12 and the immediately adjacent addresses. It checks both private filters with CIDR enabled and disabled to catch regressions that narrow or widen the private range. The implementation is unchanged.

Validation:

  • 73 IP tests passed.
  • All 1,582 tests passed on Python 3.11, 3.12, 3.13, and 3.14.
  • tox lint, type, format, and SAST checks passed.
  • git diff --check passed.

Developed and validated with assistance from OpenAI Codex.

@mjanthony819 mjanthony819 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice regression net. The four addresses pin both edges of 172.16.0.0/12 against the prefix regex in _check_private_ip, and exercising cidr=True/False covers both the IPv4Network and IPv4Address paths. I ran the new cases on top of 22786cc: all 8 pass.

One additive suggestion: the same four addresses with private left at its default (None) currently all validate, because the filter is skipped entirely. That default path is what most callers rely on, and a regression that started applying the filter by default would slip past these tests. Pinning it is cheap:

@pytest.mark.parametrize(
    "address",
    ["172.15.255.255", "172.16.0.0", "172.31.255.255", "172.32.0.0"],
)
def test_ipv4_private_172_range_default_unfiltered(address: str):
    """Test the default (no private filter) accepts both edges of 172.16.0.0/12."""
    assert ipv4(address, cidr=True) is True
    assert ipv4(address, cidr=False) is True

Verified locally that all four return True today under the default. Not blocking, just an extra invariant while the boundaries are being pinned.

AI assistance covered the analysis and this review text.

This branch has not been deployed

No deployments
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