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:
parent
dec3d00b28
commit
402d784b8f
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user