diff options
Diffstat (limited to 'src/path/filepath/path.go')
-rw-r--r-- | src/path/filepath/path.go | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 32dd887998..326ca006b2 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -52,6 +52,11 @@ func (b *lazybuf) append(c byte) { b.w++ } +func (b *lazybuf) prepend(prefix ...byte) { + b.buf = append(prefix, b.buf...) + b.w += len(prefix) +} + func (b *lazybuf) string() string { if b.buf == nil { return b.volAndPath[:b.volLen+b.w] @@ -146,18 +151,6 @@ func Clean(path string) string { if rooted && out.w != 1 || !rooted && out.w != 0 { out.append(Separator) } - // If a ':' appears in the path element at the start of a Windows path, - // insert a .\ at the beginning to avoid converting relative paths - // like a/../c: into c:. - if runtime.GOOS == "windows" && out.w == 0 && out.volLen == 0 && r != 0 { - for i := r; i < n && !os.IsPathSeparator(path[i]); i++ { - if path[i] == ':' { - out.append('.') - out.append(Separator) - break - } - } - } // copy element for ; r < n && !os.IsPathSeparator(path[r]); r++ { out.append(path[r]) @@ -170,6 +163,21 @@ func Clean(path string) string { out.append('.') } + if runtime.GOOS == "windows" && out.volLen == 0 && out.buf != nil { + // If a ':' appears in the path element at the start of a Windows path, + // insert a .\ at the beginning to avoid converting relative paths + // like a/../c: into c:. + for _, c := range out.buf { + if os.IsPathSeparator(c) { + break + } + if c == ':' { + out.prepend('.', Separator) + break + } + } + } + return FromSlash(out.string()) } |