From da0d1a44bac379f5acedb1933f85400de08f4ac6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 26 Sep 2018 21:10:21 +0000 Subject: all: use strings.ReplaceAll and bytes.ReplaceAll where applicable I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/path/filepath/path.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/path/filepath/path.go') diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 1508137a33..aba1717e7d 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -166,7 +166,7 @@ func ToSlash(path string) string { if Separator == '/' { return path } - return strings.Replace(path, string(Separator), "/", -1) + return strings.ReplaceAll(path, string(Separator), "/") } // FromSlash returns the result of replacing each slash ('/') character @@ -176,7 +176,7 @@ func FromSlash(path string) string { if Separator == '/' { return path } - return strings.Replace(path, "/", string(Separator), -1) + return strings.ReplaceAll(path, "/", string(Separator)) } // SplitList splits a list of paths joined by the OS-specific ListSeparator, -- cgit v1.3 From d1f7470c217691dca4e339c77bf8c4175b8db168 Mon Sep 17 00:00:00 2001 From: QtRoS Date: Tue, 25 Sep 2018 00:01:39 +0300 Subject: path/filepath: fix Windows-specific Clean bug Fixes #27791 Change-Id: I762fa663379086c24cb4ddc8233a2c0a82b1238e Reviewed-on: https://go-review.googlesource.com/137055 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/path/filepath/path.go | 11 ++++++++--- src/path/filepath/path_test.go | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/path/filepath/path.go') diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index aba1717e7d..bbb90306a7 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -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 { diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index e1b5ad1d40..eddae4755b 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -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) { -- cgit v1.3