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
}
return c == '\\' || c == '/'
}
+// reservedNames lists reserved Windows names. Search for PRN in
+// https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
+// for details.
+var reservedNames = []string{
+ "CON", "PRN", "AUX", "NUL",
+ "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
+ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
+}
+
+// isReservedName returns true, if path is Windows reserved name.
+// See reservedNames for the full list.
+func isReservedName(path string) bool {
+ if len(path) == 0 {
+ return false
+ }
+ for _, reserved := range reservedNames {
+ if strings.EqualFold(path, reserved) {
+ return true
+ }
+ }
+ 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