Skip to content

fix: prevent double percent-encoding of URL path segments#306

Merged
amountainram merged 2 commits into
mainfrom
fix/escaped-paths
May 13, 2026
Merged

fix: prevent double percent-encoding of URL path segments#306
amountainram merged 2 commits into
mainfrom
fix/escaped-paths

Conversation

@amountainram

Copy link
Copy Markdown
Contributor

Description

Fixes a bug where branch/revision names containing slashes were double
percent-encoded in API request URLs. For example, feat/external-idp
was encoded as feat%252Fexternal-idp instead of feat%2Fexternal-idp.

Root Cause

Request.URL() in internal/client/request.go assigned the encoded
apiPath (from EscapedPath(), containing %2F) directly to
url.Path, which in Go's net/url package is the decoded field.
When url.String() later serialized the URL, it called EscapedPath()
again, re-encoding the % character itself (%%25), producing
%252F.

Changes

  • In Request.URL(), detect when the assembled path contains
    percent-encoded segments and properly split into decoded url.Path
    and encoded url.RawPath.
  • Added a test case to TestRequestURL verifying the final URL string
    preserves percent-encoded path segments.
  • Fixed test assertions in TestDescribeProjectCmd to check RawPath
    instead of Path for encoded segments, matching correct HTTP
    behavior.

Testing

All existing tests pass. New test added covering the specific scenario.

The URL() method assigned the encoded apiPath (containing %2F) directly
to url.Path, which is Go's decoded field. When url.String() serialized
the URL, it re-encoded the percent sign (%2F -> %252F), causing branch
and revision names with slashes to be mangled in API requests.

Set url.RawPath alongside url.Path so Go's URL serialization preserves
the original percent-encoding.
The URL() method assigned the encoded apiPath (containing %2F) directly
to url.Path, which is Go's decoded field. When url.String() serialized
the URL, it re-encoded the percent sign (%2F -> %252F), causing branch
and revision names with slashes to be mangled in API requests.

Set url.RawPath alongside url.Path so Go's URL serialization preserves
the original percent-encoding.
@amountainram amountainram marked this pull request as ready for review May 12, 2026 20:32
@amountainram amountainram requested a review from a team as a code owner May 12, 2026 20:32
@amountainram amountainram merged commit f4d97e8 into main May 13, 2026
10 checks passed
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.

2 participants