Skip to content

Use uint.TryFormat to fix TODO in IPAddressParser #117300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stephentoub
Copy link
Member

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 01:34
Copy link
Contributor

@Copilot 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 replaces the manual digit-by-digit formatting of the IPv6 scope ID with a call to uint.TryFormat, removing the TODO and reducing code complexity.

  • Added a Debug.Assert to ensure TChar is either byte or char.
  • Replaced manual stackalloc formatting with a single TryFormat call for both byte and char.
  • Removed the old loop-based formatting and related TODO comment.
Comments suppressed due to low confidence (1)

src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs:225

  • Add unit tests covering the new TryFormat logic for both TChar = char and TChar = byte to ensure the IPv6 scope ID formatting is exercised in all scenarios.
                bool formatted = typeof(TChar) == typeof(byte) ?

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

used.CopyTo(destination.Slice(pos));
pos += used.Length;
int bytesWritten;
bool formatted = typeof(TChar) == typeof(byte) ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to switch to TryFormat in the local functions FormatByte and AppendHex in this file too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants