Skip to content

feat: Use IPNetwork.TryParse() for CIDR parsing#1122

Merged
BenjaminMichaelis merged 1 commit into
mainfrom
benjaminmichaelis/cidr-parsing-choice
May 17, 2026
Merged

feat: Use IPNetwork.TryParse() for CIDR parsing#1122
BenjaminMichaelis merged 1 commit into
mainfrom
benjaminmichaelis/cidr-parsing-choice

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

@BenjaminMichaelis BenjaminMichaelis commented May 17, 2026

Motivation

The CIDR parsing logic was implemented with a custom helper that manually split strings, parsed integers, and validated prefix lengths. The .NET framework provides a built-in and thoroughly validated IPNetwork.TryParse() API that handles all of this, eliminating the need for custom parsing code.

Changes

  • Removed the TryParseCidr() wrapper method entirely
  • Inlined CIDR validation directly in the loop using IPNetwork.TryParse()
  • Removed unused System.Net.Sockets import

This eliminates unnecessary indirection while maintaining identical behavior and improving maintainability by relying on framework-tested APIs.

Copilot AI review requested due to automatic review settings May 17, 2026 07:43
@BenjaminMichaelis BenjaminMichaelis force-pushed the benjaminmichaelis/cidr-parsing-choice branch from 94f4535 to 0827cdd Compare May 17, 2026 07:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR simplifies trusted proxy CIDR parsing by replacing custom parsing logic with the framework-provided System.Net.IPNetwork.TryParse() API.

Changes:

  • Removed manual CIDR string splitting, IP parsing, prefix validation, and network construction.
  • Removed the now-unused System.Net.Sockets import.

Replace custom TryParseCidr implementation with the built-in System.Net.IPNetwork.TryParse() API. This eliminates manual parsing logic and leverages the framework's validated implementation.

Changes:
- Simplified TryParseCidr to one-liner using IPNetwork.TryParse
- Removed manual split/validation of prefix length and address family
- Removed unused AddressFamily import
@BenjaminMichaelis BenjaminMichaelis force-pushed the benjaminmichaelis/cidr-parsing-choice branch from 0827cdd to 3731a30 Compare May 17, 2026 07:48
@BenjaminMichaelis BenjaminMichaelis changed the title Use IPNetwork.TryParse() for CIDR parsing feat: Use IPNetwork.TryParse() for CIDR parsing May 17, 2026
@BenjaminMichaelis BenjaminMichaelis merged commit 6d7ac55 into main May 17, 2026
8 checks passed
@BenjaminMichaelis BenjaminMichaelis deleted the benjaminmichaelis/cidr-parsing-choice branch May 17, 2026 07:52
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