Skip to content

Document Unicode encoding behavior in Uri.GetLeftPart method #11479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 19, 2025

The Uri.GetLeftPart method performs Unicode character encoding and normalization under the hood, which can cause subtle bugs when developers expect simple string manipulation. This was reported as an issue where users were using GetLeftPart to remove SAS tokens but discovered it does more than just string truncation.

Changes Made

Added comprehensive documentation to the Uri.GetLeftPart method to clarify:

  1. Important warning: Added a prominent callout explaining that the method performs Unicode character encoding and normalization
  2. Behavioral clarification: Explicitly states it's not a simple string manipulation method and that the returned string may differ from the original URI
  3. Implementation details: Documents that GetLeftPart is equivalent to calling GetComponents with specific UriComponents flags
  4. Example mapping: Shows how GetLeftPart(UriPartial.Authority) maps to the corresponding GetComponents call

Example of the documentation change:

> [!IMPORTANT]
> The GetLeftPart method performs Unicode character encoding and normalization as part of its processing. It is not a simple string manipulation method. The returned string may differ from the original URI string due to this encoding behavior.

The GetLeftPart method is equivalent to calling GetComponents with the appropriate UriComponents flags. For example:
- `GetLeftPart(UriPartial.Authority)` is equivalent to `GetComponents(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped)`

This documentation will help developers understand the method's true behavior and avoid unexpected results when using it for scenarios like removing query parameters or fragments from URIs.

Fixes #11253.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] .GetLeftPart does unicode character encoding under the hood Document Unicode encoding behavior in Uri.GetLeftPart method Jun 19, 2025
Copilot finished work on behalf of jeffhandley June 19, 2025 07:02
@Copilot Copilot AI requested a review from jeffhandley June 19, 2025 07:02
Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. @dotnet/ncl, how about someone from your team?

@jeffhandley jeffhandley marked this pull request as ready for review June 20, 2025 01:48
@jeffhandley jeffhandley requested a review from a team as a code owner June 20, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.GetLeftPart does unicode character encoding under the hood
3 participants