Fix empty host parsing regression#124431
Merged
MihaZupan merged 1 commit intodotnet:mainfrom Feb 15, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
stephentoub
reviewed
Feb 14, 2026
src/libraries/System.Private.Uri/tests/FunctionalTests/UriCreateStringTests.cs
Show resolved
Hide resolved
stephentoub
approved these changes
Feb 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression introduced in #121671 where URIs with no host but with a port (e.g., tcp://:11111) were incorrectly accepted instead of throwing a UriFormatException. The fix restores the original behavior by adding a check to ensure that port parsing only occurs when a non-empty host is present.
Changes:
- Fixed the host parsing logic to require a non-zero
hostLengthbefore attempting to parse a port - Added comprehensive test coverage for unknown schemes with empty hosts followed by ports
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/Uri.cs | Added && hostLength != 0 condition to port parsing check to prevent parsing ports when no host is present |
| src/libraries/System.Private.Uri/tests/FunctionalTests/UriCreateStringTests.cs | Added test cases for unknown schemes with empty hosts and ports, including variations with paths, queries, and fragments |
b797b51 to
0b39c97
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #124426
Regressed in #121671
The previous check had
end < length, which wasn't so much a range check as a check thatendwas updatedruntime/src/libraries/System.Private.Uri/src/System/Uri.cs
Line 3967 in 7fb0240