Remove unsafe code from Uri PrivateParseMinimal, CheckAuthorityHelper, and related helpers#121671
Merged
MihaZupan merged 2 commits intodotnet:mainfrom Nov 24, 2025
Merged
Conversation
…, and related helpers
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes unsafe code from URI parsing methods by converting pointer-based implementations to use ReadOnlySpan<char>. The changes eliminate the use of fixed statements and pointer arithmetic while preserving the original parsing logic.
Key Changes:
- Converted
IriHelper.EscapeUnescapeIrifrom unsafe pointer-based to safe span-based implementation - Converted
UncNameHelper.IsValidto acceptReadOnlySpan<char>instead ofchar*pointer - Converted
Uri.PrivateParseMinimal,CheckAuthorityHelper, andGetHostViaCustomSyntaxto use spans instead of pointers
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.Uri/tests/UnitTests/IriEscapeUnescapeTest.cs | Simplified tests by removing unsafe code and HeapCheck buffer validation class, now calling IriHelper.EscapeUnescapeIri directly |
| src/libraries/System.Private.Uri/src/System/UriExt.cs | Updated EscapeUnescapeIri wrapper to use span-based API instead of unsafe pointer-based call |
| src/libraries/System.Private.Uri/src/System/IriHelper.cs | Converted EscapeUnescapeIri from unsafe pointer arithmetic to safe span indexing while preserving all parsing logic |
| src/libraries/System.Private.Uri/src/System/UncNameHelper.cs | Converted IsValid from unsafe pointer-based to span-based, using uint cast for bounds checking and returning output parameter for name length |
| src/libraries/System.Private.Uri/src/System/Uri.cs | Removed unsafe code from PrivateParseMinimal, CheckAuthorityHelper, and GetHostViaCustomSyntax by converting to span-based parsing while maintaining all parsing behavior and edge cases |
EgorBo
reviewed
Nov 16, 2025
gfoidl
reviewed
Nov 16, 2025
xtqqczze
reviewed
Nov 17, 2025
EgorBo
approved these changes
Nov 24, 2025
This was referenced Nov 24, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Removes unsafe code from
PrivateParseMinimal,EscapeUnescapeIri,UncNameHelper.IsValid,GetHostViaCustomSyntax,CheckAuthorityHelper.