SanitizeFileName sanitizes the given filename
(fileName string)
| 30 | |
| 31 | // SanitizeFileName sanitizes the given filename |
| 32 | func SanitizeFileName(fileName string) string { |
| 33 | // filepath.Clean to clean the path |
| 34 | cleanName := filepath.Clean(fileName) |
| 35 | // filepath.Base to ensure we only get the final element, not any directory path |
| 36 | baseName := filepath.Base(cleanName) |
| 37 | // Replace any remaining tricky characters that might have survived cleaning |
| 38 | safeName := strings.ReplaceAll(baseName, "..", "") |
| 39 | return safeName |
| 40 | } |
| 41 | |
| 42 | func GenerateUniqueFileName(dir, baseName, ext string) string { |
| 43 | counter := 1 |