Skip to content

Replace regex-based IP validation with ipaddress module#7

Merged
jacobseunglee merged 2 commits into
refactor/claude-copilotfrom
copilot/sub-pr-6
Oct 29, 2025
Merged

Replace regex-based IP validation with ipaddress module#7
jacobseunglee merged 2 commits into
refactor/claude-copilotfrom
copilot/sub-pr-6

Conversation

Copilot AI commented Oct 29, 2025

Copy link
Copy Markdown

Addresses feedback from PR #6 to fix incomplete IPv6 validation that only supported full notation.

Changes

  • Replace regex patterns with ipaddress.ip_address() from Python stdlib
  • Supports all valid IPv6 formats: compressed notation (::1), mixed notation (::ffff:192.0.2.1), link-local addresses
  • Reduces code from 16 lines to 9 lines while improving correctness

Before/After

# Before: regex only matched full IPv6 notation
ipv6_pattern = r'^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$'
if not (re.match(ipv4_pattern, ip) or re.match(ipv6_pattern, ip)):
    raise ValidationError(f"Invalid IP address format: {ip}")

# After: handles all RFC-compliant formats
try:
    ipaddress.ip_address(ip)
    return ip
except ValueError:
    raise ValidationError(f"Invalid IP address format: {ip}")

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jacobseunglee <66867022+jacobseunglee@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback from PR #6 on code refactoring Replace regex-based IP validation with ipaddress module Oct 29, 2025
Copilot AI requested a review from jacobseunglee October 29, 2025 01:54
@jacobseunglee jacobseunglee marked this pull request as ready for review October 29, 2025 02:06
@jacobseunglee jacobseunglee merged commit ecfd8f8 into refactor/claude-copilot Oct 29, 2025
@jacobseunglee jacobseunglee deleted the copilot/sub-pr-6 branch October 29, 2025 02:06
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