Skip to content

Conversation

@MihaZupan
Copy link
Member

Removes unsafe code from PrivateParseMinimal, EscapeUnescapeIri, UncNameHelper.IsValid, GetHostViaCustomSyntax, CheckAuthorityHelper.

@MihaZupan MihaZupan added this to the 11.0.0 milestone Nov 15, 2025
@MihaZupan MihaZupan self-assigned this Nov 15, 2025
@MihaZupan MihaZupan marked this pull request as ready for review November 16, 2025 02:57
@MihaZupan MihaZupan requested review from a team and Copilot November 16, 2025 02:57
Copilot finished reviewing on behalf of MihaZupan November 16, 2025 03:01
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 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.EscapeUnescapeIri from unsafe pointer-based to safe span-based implementation
  • Converted UncNameHelper.IsValid to accept ReadOnlySpan<char> instead of char* pointer
  • Converted Uri.PrivateParseMinimal, CheckAuthorityHelper, and GetHostViaCustomSyntax to 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

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