MCPcopy
hub / github.com/cli/cli / sanitizeFileName

Function sanitizeFileName

pkg/cmd/release/upload/upload.go:134–156  ·  view source on GitHub ↗

this method attempts to mimic the same functionality on the client that the platform does on uploaded assets in order to allow the --clobber logic work correctly, since that feature is one that only exists in the client

(name string)

Source from the content-addressed store, hash-verified

132// uploaded assets in order to allow the --clobber logic work correctly, since that feature is
133// one that only exists in the client
134func sanitizeFileName(name string) string {
135 value := text.RemoveDiacritics(name)
136 // Stripped all non-ascii characters, provide default name.
137 if strings.HasPrefix(value, ".") {
138 value = "default" + value
139 }
140
141 // Replace special characters with the separator
142 value = regexp.MustCompile(`(?i)[^a-z0-9\-_\+@]+`).ReplaceAllLiteralString(value, ".")
143
144 // No more than one of the separator in a row.
145 value = regexp.MustCompile(`\.{2,}`).ReplaceAllLiteralString(value, ".")
146
147 // Remove leading/trailing separator.
148 value = strings.Trim(value, ".")
149
150 // Just file extension left, add default name.
151 if name != value && !strings.Contains(value, ".") {
152 value = "default." + value
153 }
154
155 return value
156}

Callers 2

uploadRunFunction · 0.85
Test_SanitizeFileNameFunction · 0.85

Calls 2

RemoveDiacriticsFunction · 0.92
ContainsMethod · 0.80

Tested by 1

Test_SanitizeFileNameFunction · 0.68