MCPcopy
hub / github.com/mudler/LocalAI / SanitizeFileName

Function SanitizeFileName

pkg/utils/path.go:32–40  ·  view source on GitHub ↗

SanitizeFileName sanitizes the given filename

(fileName string)

Source from the content-addressed store, hash-verified

30
31// SanitizeFileName sanitizes the given filename
32func 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
42func GenerateUniqueFileName(dir, baseName, ext string) string {
43 counter := 1

Callers 1

path_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected