From ee163197a879cf19aa9758bc544c717445284311 Mon Sep 17 00:00:00 2001 From: Federico Guerinoni Date: Tue, 7 Oct 2025 01:13:14 +0200 Subject: [PATCH] path/filepath: return cleaned path from Rel As the doc says, Rel should return a cleaned path. Fixes #75763 Change-Id: Ic0f5a3b1da3cc4cf3c31fdb1a88ebcc4ea6f9169 Reviewed-on: https://go-review.googlesource.com/c/go/+/709675 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Reviewed-by: Sean Liao Auto-Submit: Sean Liao Reviewed-by: Carlos Amedee --- src/path/filepath/path.go | 2 +- src/path/filepath/path_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 5ffd9f0b6c..dc6975242a 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -248,7 +248,7 @@ func Rel(basepath, targpath string) (string, error) { buf[n] = Separator copy(buf[n+1:], targ[t0:]) } - return string(buf), nil + return Clean(string(buf)), nil } return targ[t0:], nil } diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 7ea02a7c28..efdb3c6035 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -1506,6 +1506,7 @@ var reltests = []RelTests{ {"/../../a/b", "/../../a/b/c/d", "c/d"}, {".", "a/b", "a/b"}, {".", "..", ".."}, + {"", "../../.", "../.."}, // can't do purely lexically {"..", ".", "err"}, -- 2.52.0