]> Cypherpunks.ru repositories - gostls13.git/commitdiff
path/filepath: make Rel handle Windows UNC share
authorAman Gupta <aman@tmm1.net>
Fri, 4 Sep 2020 23:07:12 +0000 (16:07 -0700)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 25 Mar 2021 08:43:17 +0000 (08:43 +0000)
Fixes #41230

Change-Id: Iea15e4ae6d56328333fd22de5d78dfcad78ef1bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/253197
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/path/filepath/path.go
src/path/filepath/path_test.go

index 2e7b439355a669bf830bab9f5131a52dbaceced9..28b30b1ae7c313fff8a4ea75c8e8e292f7902a2a 100644 (file)
@@ -275,7 +275,11 @@ func Rel(basepath, targpath string) (string, error) {
        targ = targ[len(targVol):]
        if base == "." {
                base = ""
+       } else if base == "" && volumeNameLen(baseVol) > 2 /* isUNC */ {
+               // Treat any targetpath matching `\\host\share` basepath as absolute path.
+               base = string(Separator)
        }
+
        // Can't use IsAbs - `\a` and `a` are both relative in Windows.
        baseSlashed := len(base) > 0 && base[0] == Separator
        targSlashed := len(targ) > 0 && targ[0] == Separator
index 8616256ac0726e9a1a568c034d2fa574379a4691..1d9889d320cd3be2c725cbf28d1936358efb1daf 100644 (file)
@@ -1227,6 +1227,7 @@ var winreltests = []RelTests{
        {`C:\Projects`, `c:\projects\src`, `src`},
        {`C:\Projects`, `c:\projects`, `.`},
        {`C:\Projects\a\..`, `c:\projects`, `.`},
+       {`\\host\share`, `\\host\share\file.txt`, `file.txt`},
 }
 
 func TestRel(t *testing.T) {