Skip to content

Conversation

@MihaZupan
Copy link
Member

The fix in #36429 wasn't quite right because DOS-like Uris may appear with non-file schemes (e.g. custom:C:/uri).
This changes the condition to handle such inputs (Dos || Unix instead of File && !Unc).

The change with checking for InFact(Flags.AuthorityFound) is specific for custom schemes with DOS-like inputs.
It ensures that custom:C:/uri and custom:C:/üri (with non-ASCII or not) behave similarly with ToString and preserve whether : vs :// was used.

Fixes #94572

@MihaZupan MihaZupan added this to the 11.0.0 milestone Nov 24, 2025
@MihaZupan MihaZupan self-assigned this Nov 24, 2025
@MihaZupan MihaZupan marked this pull request as ready for review November 25, 2025 08:34
@MihaZupan MihaZupan requested review from a team and Copilot November 25, 2025 08:34
Copilot finished reviewing on behalf of MihaZupan November 25, 2025 08:39
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 bug in URI ToString() handling for DOS-like paths in custom (non-file) schemes. The issue was that the previous fix only handled file:// URIs, but DOS-like paths can appear with any custom scheme (e.g., custom:C:/uri).

Key Changes:

  • Modified the condition in ParseRemaining to check for DOS/Unix paths regardless of scheme (not just file://)
  • Updated CreateUriInfo to handle cases where AuthorityFound is set but there are no double slashes (DOS path immediately after scheme)
  • Added logic to preserve whether : vs :// was used in the original URI for custom schemes with DOS paths

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Private.Uri/src/System/Uri.cs Fixed URI string reconstruction logic to handle DOS paths in custom schemes; added conditional handling for authority delimiters based on whether the original URI used : or ://
src/libraries/System.Private.Uri/tests/FunctionalTests/UriTests.cs Added comprehensive test cases for DOS paths in file:// scheme and custom schemes, including vsmacros scheme behavior

@MihaZupan MihaZupan merged commit a56f65e into dotnet:main Nov 25, 2025
91 of 92 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.

System.Uri.ToString result is incorrect when combining custom scheme with DOS-style path containing multibyte Unicode character

2 participants