mirror of
https://github.com/harness/drone.git
synced 2025-05-31 11:43:15 +00:00
20 lines
443 B
Go
20 lines
443 B
Go
package api
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// CleanUploadFileName Trims a filename and returns empty string if it is a .git directory
|
|
func CleanUploadFileName(name string) string {
|
|
// Rebase the filename
|
|
name = strings.Trim(path.Clean("/"+name), "/")
|
|
// Git disallows any filenames to have a .git directory in them.
|
|
for _, part := range strings.Split(name, "/") {
|
|
if strings.ToLower(part) == ".git" {
|
|
return ""
|
|
}
|
|
}
|
|
return name
|
|
}
|