Skip to content

Commit 7396189

Browse files
committed
Revert "path/filepath: change IsAbs("NUL") to return true"
This reverts commit d154ef6. This change made IsAbs return true for certain reserved filenames, but does not consistently detect reserved names. For example, "./COM1", "//./COM1", and (on some Windows versions) "COM1.txt" all refer to the COM1 device, but IsAbs detects none of them. Since NUL is not an absolute path, do not attempt to detect it or other device paths in IsAbs. See #56217 for more discussion of IsAbs and device paths. For #56217. Change-Id: If4bf81c7e1a2e8842206c7c5268555102140dae8 Reviewed-on: https://go-review.googlesource.com/c/go/+/448898 Reviewed-by: Michael Knyszek <[email protected]> Run-TryBot: Damien Neil <[email protected]> Reviewed-by: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 61c5757 commit 7396189

File tree

2 files changed

+0
-23
lines changed

2 files changed

+0
-23
lines changed

src/path/filepath/path_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,6 @@ func TestIsAbs(t *testing.T) {
897897
for _, test := range isabstests {
898898
tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs})
899899
}
900-
// Test reserved names.
901-
tests = append(tests, IsAbsTest{os.DevNull, true})
902-
tests = append(tests, IsAbsTest{"NUL", true})
903-
tests = append(tests, IsAbsTest{"nul", true})
904-
tests = append(tests, IsAbsTest{"CON", true})
905900
} else {
906901
tests = isabstests
907902
}

src/path/filepath/path_windows.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,8 @@ func toUpper(c byte) byte {
2020
return c
2121
}
2222

23-
// isReservedName returns true if path is a Windows reserved name.
24-
func isReservedName(path string) bool {
25-
// For details, search for PRN in
26-
// https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file.
27-
if 3 <= len(path) && len(path) <= 4 {
28-
switch string([]byte{toUpper(path[0]), toUpper(path[1]), toUpper(path[2])}) {
29-
case "CON", "PRN", "AUX", "NUL":
30-
return len(path) == 3
31-
case "COM", "LPT":
32-
return len(path) == 4 && '1' <= path[3] && path[3] <= '9'
33-
}
34-
}
35-
return false
36-
}
37-
3823
// IsAbs reports whether the path is absolute.
3924
func IsAbs(path string) (b bool) {
40-
if isReservedName(path) {
41-
return true
42-
}
4325
l := volumeNameLen(path)
4426
if l == 0 {
4527
return false

0 commit comments

Comments
 (0)