diff options
Diffstat (limited to 'modules/repofiles/repofiles.go')
-rw-r--r-- | modules/repofiles/repofiles.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/repofiles/repofiles.go b/modules/repofiles/repofiles.go new file mode 100644 index 0000000000..1fc900490c --- /dev/null +++ b/modules/repofiles/repofiles.go @@ -0,0 +1,23 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file.package repofiles + +package repofiles + +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 +} |