Use Go rules for Windows filename components

This commit is contained in:
2026-10-24 19:20:54 +00:00
parent 087050fa25
commit 2fedb0307f
4 changed files with 68 additions and 38 deletions

View File

@@ -129,31 +129,33 @@ func TestFilenameComponentValidation(t *testing.T) {
}
}
if runtime.GOOS == "windows" {
for _, value := range []string{"CON", "nul.txt", "name.", "bad:name"} {
for _, value := range []string{"CON", "CONIN$", "CONOUT$", "name.", "bad:name", "bad\x01name"} {
if validFilenameComponent(value) {
t.Errorf("Windows component %q unexpectedly accepted", value)
}
}
} else {
for _, value := range []string{"name with spaces", "naïve"} {
if !validFilenameComponent(value) {
t.Errorf("host-valid component %q rejected", value)
// Device names with extensions depend on the Windows version. Match
// Go's platform-aware decision instead of imposing a blanket ban.
for _, value := range []string{"nul.txt", "COM¹.log", "LPT³.txt", "CON.extra.yml"} {
if got, want := validFilenameComponent(value), filepath.IsLocal(value); got != want {
t.Errorf("Windows component %q validity = %v, want Go's %v", value, got, want)
}
}
} else {
for _, value := range []string{"CONIN$", "CONOUT$", "nul.txt"} {
if !validFilenameComponent(value) {
t.Errorf("Windows component restriction applied to this host: %q", value)
}
}
}
for _, value := range []string{"name with spaces", "naïve"} {
if !validFilenameComponent(value) {
t.Errorf("host-valid component %q rejected", value)
}
}
if diagnostics := validateSearch(SearchDirectory("configs", DirectorySearchOptions{Filenames: []FilenameGroup{CustomFilenames("bad/name")}}), ""); len(diagnostics) == 0 {
t.Fatal("invalid custom filename was not retained for validation")
}
for _, value := range []string{"CON", "nul.txt", "COM¹.log", "LPT³.txt", "name.", "bad:name", "bad\x01name"} {
if validWindowsFilenameComponent(value) {
t.Errorf("Windows component %q unexpectedly accepted", value)
}
}
for _, value := range []string{"name with spaces", "naïve"} {
if !validWindowsFilenameComponent(value) {
t.Errorf("valid Windows component %q rejected", value)
}
}
}
func TestSearchCandidatesPreserveDirectoryAndGroupOrder(t *testing.T) {