Skip to content

Commit df40c66

Browse files
authored
Fix windows cronjob (#1891)
* Fix Windows filename issue in scheduled support bundles * fix bugbot
1 parent 6c5c310 commit df40c66

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/collect/util.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,19 @@ func DeterministicIDForCollector(collector *troubleshootv1beta2.Collect) string
8080
}
8181

8282
func selectorToString(selector []string) string {
83-
return strings.Replace(strings.Join(selector, "-"), "=", "-", -1)
83+
result := strings.Replace(strings.Join(selector, "-"), "=", "-", -1)
84+
// Sanitize characters that are invalid in Windows filenames: < > : " / \ | ? *
85+
// Replace them with underscores to ensure cross-platform compatibility
86+
result = strings.ReplaceAll(result, "*", "all")
87+
result = strings.ReplaceAll(result, "?", "_")
88+
result = strings.ReplaceAll(result, ":", "_")
89+
result = strings.ReplaceAll(result, "<", "_")
90+
result = strings.ReplaceAll(result, ">", "_")
91+
result = strings.ReplaceAll(result, "|", "_")
92+
result = strings.ReplaceAll(result, "\"", "_")
93+
result = strings.ReplaceAll(result, "/", "_")
94+
result = strings.ReplaceAll(result, "\\", "_")
95+
return result
8496
}
8597

8698
func pathToString(path string) string {

0 commit comments

Comments
 (0)