From 402d784b8fc0a7914955eb168ea288338e2025ff Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Fri, 4 Sep 2020 16:07:12 -0700 Subject: 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 Trust: Alex Brainman Trust: Emmanuel Odeke Run-TryBot: Alex Brainman TryBot-Result: Go Bot --- src/path/filepath/path.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/path/filepath/path.go') diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 2e7b439355..28b30b1ae7 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -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 -- cgit v1.3