Skip to content

Commit

Permalink
path/filepath: revert "fix Windows-specific Clean bug"
Browse files Browse the repository at this point in the history
Revert CL 137055, which changed Clean("\\somepath\dir\") to return
"\\somepath\dir" on Windows. It's not entirely clear this is correct,
as this path is really "\\server\share\", and as such the trailing
slash may be the path on that share, much like "C:\". In any case, the
change broke existing code, so roll it back for now and rethink for 1.13.

Updates #27791
Fixes #30307

Change-Id: I69200b1efe38bdb6d452b744582a2bfbb3acbcec
Reviewed-on: https://go-review.googlesource.com/c/163077
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
  • Loading branch information
ianlancetaylor committed Feb 20, 2019
1 parent dace654 commit 153c0da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/path/filepath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,14 @@ 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 out; w is index of next byte to write.
// dotdot is index in out where .. must stop, either because
// writing to buf; w is index of next byte to write.
// dotdot is index in buf 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 {
Expand Down
3 changes: 0 additions & 3 deletions src/path/filepath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ 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) {
Expand Down

0 comments on commit 153c0da

Please sign in to comment.