mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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
2 changed files with 5 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue