MCPcopy Create free account
hub / github.com/github/gh-aw / sanitizePath

Function sanitizePath

pkg/parser/import_cache.go:24–31  ·  view source on GitHub ↗

sanitizePath converts a file path to a safe filename by using filepath.Clean and replacing directory separators with underscores

(path string)

Source from the content-addressed store, hash-verified

22// sanitizePath converts a file path to a safe filename by using filepath.Clean
23// and replacing directory separators with underscores
24func sanitizePath(path string) string {
25 // Clean the path to remove any ".." or other suspicious elements
26 cleaned := filepath.Clean(path)
27 // Replace directory separators with underscores to create a flat filename
28 // This prevents directory traversal while preserving path uniqueness
29 sanitized := strings.ReplaceAll(cleaned, string(filepath.Separator), "_")
30 return sanitized
31}
32
33// validatePathComponents validates that path components don't contain malicious sequences
34func validatePathComponents(owner, repo, path, sha string) error {

Callers 3

GetMethod · 0.85
SetMethod · 0.85
TestSanitizePathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSanitizePathFunction · 0.68