From 785e1d9dc06d1f2efc1182676855980068d9176f Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:49:42 +0300 Subject: [PATCH] Preserve escapes when resolving relative paths Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> --- core_url.go | 3 ++- core_url_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core_url.go b/core_url.go index 00d7db1..fd3ea13 100644 --- a/core_url.go +++ b/core_url.go @@ -67,7 +67,8 @@ func (ub *urlBuilder) URL() (u *url.URL, err error) { ) u.Host = cmp.Or(ub.host, u.Host) for _, p := range ub.paths { - u.Path = u.ResolveReference(&url.URL{Path: p}).Path + resolved := u.ResolveReference(&url.URL{Path: p}) + u.Path, u.RawPath = resolved.Path, resolved.RawPath } if len(ub.params) > 0 { q := u.Query() diff --git a/core_url_test.go b/core_url_test.go index 0f8cc72..f47c285 100644 --- a/core_url_test.go +++ b/core_url_test.go @@ -92,6 +92,16 @@ var PathCases = map[string]struct { []string{"b/", "c/", "/d"}, "https://example/d", }, + "escaped-base-segment": { + "https://example/a%2Fb/", + []string{"c"}, + "https://example/a%2Fb/c", + }, + "escaped-base-parent": { + "https://example/a%2Fb/c/", + []string{"../d"}, + "https://example/a%2Fb/d", + }, } func TestCorePath(t *testing.T) {