fix(text): preserve percent-encoding in DisplayURL - #13758
Open
salarkhannn wants to merge 1 commit into
Open
Conversation
DisplayURL was reconstructing the URL with u.Hostname() + u.Path,
which decoded percent-encoded characters (e.g. %22 -> ") in the
path and lost query strings entirely. Use url.URL{}.String() instead,
which re-encodes the path via EscapedPath() and preserves the original
encoding.
Fixes cli#13546
Contributor
|
Thanks for your pull request! While it doesn't meet all of our standard requirements, it appears to be a small, focused contribution and has been routed to the team for review. Note: We still encourage linking to an issue with the |
Sanjays2402
reviewed
Jul 23, 2026
| scheme = "https" | ||
| } | ||
| return scheme + "://" + u.Hostname() + u.Path | ||
| return (&url.URL{Scheme: scheme, Host: u.Hostname(), Path: u.Path}).String() |
There was a problem hiding this comment.
building a fresh url.URL from u.Path re-encodes the decoded path, so this still drops the encoding for anything that decodes to a reserved char — e.g. ...feat%2Ffoo has Path .../feat/foo, and String() gives back feat/foo, not feat%2F foo. same class of bug the PR is fixing, just for %2F instead of %22. u.EscapedPath() preserves RawPath and covers both.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
DisplayURL was reconstructing the URL with
u.Hostname() + u.Path, which decodes percent-encoded characters (e.g.%22→") in the path and drops query strings entirely. Useurl.URL{}.String()instead, which re-encodes the path viaEscapedPath()and preserves the original encoding.Fixes #13546