]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: return cleaned path from Rel
authorFederico Guerinoni <guerinoni.federico@gmail.com>
Mon, 6 Oct 2025 23:13:14 +0000 (01:13 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 8 Oct 2025 21:27:39 +0000 (14:27 -0700)
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>
src/path/filepath/path.go
src/path/filepath/path_test.go

index 5ffd9f0b6c3fbaaa2e98d8d556656463a78055d4..dc6975242a928c476026c3ae31e78ccdbdae321e 100644 (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
 }
index 7ea02a7c2823788e8fce98db2ccfa689bdec8c91..efdb3c603592eef3942a65e4fd79bc8349dde46c 100644 (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"},