Skip to content

Preserve escaped paths when joining parsed URLs - #495

Open
harshitdeora wants to merge 1 commit into
Masterminds:masterfrom
harshitdeora:fix/preserve-escaped-url-paths
Open

harshitdeora wants to merge 1 commit into
Masterminds:masterfrom
harshitdeora:fix/preserve-escaped-url-paths

Conversation

@harshitdeora

Copy link
Copy Markdown

urlJoin (urlParse "https://example.com/a%2Fb") currently produces https://example.com/a/b: parsing discards net/url.URL.RawPath, so joining turns an encoded slash into a path separator. This can address a different resource.

Keep an optional rawPath entry when the parsed URL contains a non-default path encoding, and pass it back to net/url.URL when joining. The existing decoded path entry is unchanged. If a caller edits path, Go's URL formatter ignores an inconsistent raw path and escapes the edited path normally. The docs describe the optional entry.

Four regression cases fail before the fix and pass after, through both direct calls and template pipelines. They cover uppercase/lowercase escaped slashes, combined escaping/query/fragment, and a relative URL. A further control checks editing the decoded path.

go test ./... -skip '^TestHtmlDate$' -count=1, go vet ./..., gofmt and git diff --check pass on Windows/amd64 with Go 1.25.3. The unfiltered suite has a local timezone-dependent failure in the existing TestHtmlDate (expects June 13 for a GMT timestamp that is June 14 in IST); no date code is changed. The upstream Go/platform matrix has not been run locally.

Found while inspecting URL round-trip behavior; no existing issue is claimed.

This branch has not been deployed

No deployments
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.

1 participant