diff options
| author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2022-04-22 10:07:51 +0900 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-05-24 21:52:14 +0000 |
| commit | 9cd1818a7d019c02fa4898b3e45a323e35033290 (patch) | |
| tree | 582a5c871a2371794f242fce0310a2ebd4f6aabb /src/path/filepath/path.go | |
| parent | b6bcd0d1352578033eea0490790b6af3bf300b3f (diff) | |
| download | go-9cd1818a7d019c02fa4898b3e45a323e35033290.tar.xz | |
path/filepath: do not remove prefix "." when following path contains ":".
Fixes #52476
Change-Id: I9eb72ac7dbccd6322d060291f31831dc389eb9bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/401595
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/path/filepath/path.go')
| -rw-r--r-- | src/path/filepath/path.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index ec9e6d8a1f..de7a2c758b 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -117,9 +117,21 @@ func Clean(path string) string { case os.IsPathSeparator(path[r]): // empty path element r++ - case path[r] == '.' && (r+1 == n || os.IsPathSeparator(path[r+1])): + case path[r] == '.' && r+1 == n: // . element r++ + case path[r] == '.' && os.IsPathSeparator(path[r+1]): + // ./ element + r++ + + for r < len(path) && os.IsPathSeparator(path[r]) { + r++ + } + if out.w == 0 && volumeNameLen(path[r:]) > 0 { + // When joining prefix "." and an absolute path on Windows, + // the prefix should not be removed. + out.append('.') + } case path[r] == '.' && path[r+1] == '.' && (r+2 == n || os.IsPathSeparator(path[r+2])): // .. element: remove to last separator r += 2 |
