Skip to content

Fix empty host parsing regression#124431

Merged
MihaZupan merged 1 commit intodotnet:mainfrom
MihaZupan:uri-emptyHost
Feb 15, 2026
Merged

Fix empty host parsing regression#124431
MihaZupan merged 1 commit intodotnet:mainfrom
MihaZupan:uri-emptyHost

Conversation

@MihaZupan
Copy link
Member

Fixes #124426
Regressed in #121671

The previous check had end < length, which wasn't so much a range check as a check that end was updated

else if (end < length && pString[end] == ':')

@MihaZupan MihaZupan added this to the 11.0.0 milestone Feb 14, 2026
@MihaZupan MihaZupan self-assigned this Feb 14, 2026
Copilot AI review requested due to automatic review settings February 14, 2026 22:46
@dotnet-policy-service
Copy link
Contributor

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

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 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 hostLength before 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

@MihaZupan MihaZupan marked this pull request as ready for review February 14, 2026 23:09
Copilot AI review requested due to automatic review settings February 14, 2026 23:09
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

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

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.

[11.0-preview.1] Uri.ctor() no longer throws UriFormatException when no host specified

2 participants