lib/fs: Clarify errors for Windows filenames (fixes #8968) (#8969)

With this change, error messages include the offending characters or
name parts. Examples:

    nul.txt: name is invalid, contains Windows reserved name: "nul"
    foo>bar.txt: name is invalid, contains Windows reserved character: ">"
    foo \bar.txt: name is invalid, must not end in space or period on Windows
This commit is contained in:
Jakob Borg
2023-07-07 11:00:40 +00:00
committed by GitHub
parent 6ff5ed6d23
commit c44de2cd58
3 changed files with 16 additions and 12 deletions
+5 -1
View File
@@ -7,6 +7,7 @@
package fs
import (
"errors"
"math/rand"
"testing"
"unicode"
@@ -69,9 +70,10 @@ func TestWindowsInvalidFilename(t *testing.T) {
for _, tc := range cases {
err := WindowsInvalidFilename(tc.name)
if err != tc.err {
if !errors.Is(err, tc.err) {
t.Errorf("For %q, got %v, expected %v", tc.name, err, tc.err)
}
t.Logf("%s: %v", tc.name, err)
}
}
@@ -124,9 +126,11 @@ func benchmarkWindowsInvalidFilename(b *testing.B, name string) {
WindowsInvalidFilename(name)
}
}
func BenchmarkWindowsInvalidFilenameValid(b *testing.B) {
benchmarkWindowsInvalidFilename(b, "License.txt.gz")
}
func BenchmarkWindowsInvalidFilenameNUL(b *testing.B) {
benchmarkWindowsInvalidFilename(b, "nul.txt.gz")
}