Skip to content

Conversation

@MihaZupan
Copy link
Member

Recently broken in #121225

If the Uri ends with the host (no path/query/fragment delimiter) and has trailing whitespace, we'd pass the host including the whitespace to ParseNonCanonical which would return Invalid, hitting the Debug.Assert(result != Invalid) below.

@MihaZupan MihaZupan added this to the 11.0.0 milestone Nov 25, 2025
@MihaZupan MihaZupan requested a review from EgorBo November 25, 2025 09:42
@MihaZupan MihaZupan self-assigned this Nov 25, 2025
Copilot AI review requested due to automatic review settings November 25, 2025 09:42
@dotnet-policy-service
Copy link
Contributor

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

Copilot finished reviewing on behalf of MihaZupan November 25, 2025 09:44
Copy link
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 fixes a regression in URI IPv4 address parsing when the URI ends with the host and has trailing whitespace. The bug was introduced in PR #121225 and would cause a Debug.Assert failure when ParseNonCanonical returned Invalid after receiving a host string that included trailing whitespace.

Key Changes:

  • Fixed IPv4AddressHelper.ParseCanonicalName to pass the correct span length when calling ParseNonCanonical
  • Added a regression test to verify URIs with trailing whitespace are parsed correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.Uri/src/System/IPv4AddressHelper.cs Fixed the span slice to use explicit length (end - start) instead of implicitly including all characters from start to end of string, preventing trailing whitespace from being passed to ParseNonCanonical
src/libraries/System.Private.Uri/tests/FunctionalTests/UncTest.cs Added regression test for UNC URIs with IPv4 hosts and trailing whitespace (newline character)

@MihaZupan MihaZupan requested a review from a team November 25, 2025 12:18
Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

Thanks for noticing!

@MihaZupan MihaZupan merged commit 09e0e72 into dotnet:main Nov 25, 2025
93 of 94 checks passed
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.

2 participants