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 <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Federico Guerinoni 2025-10-07 01:13:14 +02:00 committed by Gopher Robot
parent de9da0de30
commit ee163197a8
2 changed files with 2 additions and 1 deletions

View file

@ -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
}

View file

@ -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"},