]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "path/filepath: change IsAbs("NUL") to return true"
authorDamien Neil <dneil@google.com>
Tue, 8 Nov 2022 22:21:30 +0000 (14:21 -0800)
committerDamien Neil <dneil@google.com>
Wed, 9 Nov 2022 22:06:26 +0000 (22:06 +0000)
This reverts commit d154ef60a0c88be98c70bbe1c5735fb7b1f45250.

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 <mknyszek@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/path/filepath/path_test.go
src/path/filepath/path_windows.go

index 473a89b9c50898484ec6803410afb3bc52c02c9b..382381eb4e39dca9c65f491c5b284e67e83f19d3 100644 (file)
@@ -897,11 +897,6 @@ func TestIsAbs(t *testing.T) {
                for _, test := range isabstests {
                        tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs})
                }
-               // Test reserved names.
-               tests = append(tests, IsAbsTest{os.DevNull, true})
-               tests = append(tests, IsAbsTest{"NUL", true})
-               tests = append(tests, IsAbsTest{"nul", true})
-               tests = append(tests, IsAbsTest{"CON", true})
        } else {
                tests = isabstests
        }
index 1ca59190d5d6129146430e3bb98c2c298df1217d..c754301bf450d966ab4c2f62b7a8ba10f7cbf9aa 100644 (file)
@@ -20,26 +20,8 @@ func toUpper(c byte) byte {
        return c
 }
 
-// isReservedName returns true if path is a Windows reserved name.
-func isReservedName(path string) bool {
-       // For details, search for PRN in
-       // https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file.
-       if 3 <= len(path) && len(path) <= 4 {
-               switch string([]byte{toUpper(path[0]), toUpper(path[1]), toUpper(path[2])}) {
-               case "CON", "PRN", "AUX", "NUL":
-                       return len(path) == 3
-               case "COM", "LPT":
-                       return len(path) == 4 && '1' <= path[3] && path[3] <= '9'
-               }
-       }
-       return false
-}
-
 // IsAbs reports whether the path is absolute.
 func IsAbs(path string) (b bool) {
-       if isReservedName(path) {
-               return true
-       }
        l := volumeNameLen(path)
        if l == 0 {
                return false