]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: fix Windows-specific Clean bug
authorQtRoS <mrqtros@gmail.com>
Mon, 24 Sep 2018 21:01:39 +0000 (00:01 +0300)
committerAlex Brainman <alex.brainman@gmail.com>
Sat, 29 Sep 2018 04:26:02 +0000 (04:26 +0000)
Fixes #27791
Change-Id: I762fa663379086c24cb4ddc8233a2c0a82b1238e
Reviewed-on: https://go-review.googlesource.com/137055
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/path/filepath/path.go
src/path/filepath/path_test.go

index aba1717e7d5e0c7186a0e2a91adb011730d71f0e..bbb90306a7f3891cac0492f9510f458b5d2cc9e5 100644 (file)
@@ -96,14 +96,19 @@ func Clean(path string) string {
                }
                return originalPath + "."
        }
+
+       n := len(path)
+       if volLen > 2 && n == 1 && os.IsPathSeparator(path[0]) {
+               // UNC volume name with trailing slash.
+               return FromSlash(originalPath[:volLen])
+       }
        rooted := os.IsPathSeparator(path[0])
 
        // Invariants:
        //      reading from path; r is index of next byte to process.
-       //      writing to buf; w is index of next byte to write.
-       //      dotdot is index in buf where .. must stop, either because
+       //      writing to out; w is index of next byte to write.
+       //      dotdot is index in out where .. must stop, either because
        //              it is the leading slash or it is a leading ../../.. prefix.
-       n := len(path)
        out := lazybuf{path: path, volAndPath: originalPath, volLen: volLen}
        r, dotdot := 0, 0
        if rooted {
index e1b5ad1d40c9c4e9f656314f1086de430b40413a..eddae4755be6d2066720122bc16845a2b1552ce7 100644 (file)
@@ -92,6 +92,9 @@ var wincleantests = []PathTest{
        {`//host/share/foo/../baz`, `\\host\share\baz`},
        {`\\a\b\..\c`, `\\a\b\c`},
        {`\\a\b`, `\\a\b`},
+       {`\\a\b\`, `\\a\b`},
+       {`\\folder\share\foo`, `\\folder\share\foo`},
+       {`\\folder\share\foo\`, `\\folder\share\foo`},
 }
 
 func TestClean(t *testing.T) {