1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

path/filepath: make Rel handle Windows UNC share

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>
This commit is contained in:
Aman Gupta 2020-09-04 16:07:12 -07:00 committed by Alex Brainman
parent dec3d00b28
commit 402d784b8f
2 changed files with 5 additions and 0 deletions

View 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

View 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) {