You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
630 B

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.package repofiles
  4. package repofiles
  5. import (
  6. "path"
  7. "strings"
  8. )
  9. // CleanUploadFileName Trims a filename and returns empty string if it is a .git directory
  10. func CleanUploadFileName(name string) string {
  11. // Rebase the filename
  12. name = strings.Trim(path.Clean("/"+name), " /")
  13. // Git disallows any filenames to have a .git directory in them.
  14. for _, part := range strings.Split(name, "/") {
  15. if strings.ToLower(part) == ".git" {
  16. return ""
  17. }
  18. }
  19. return name
  20. }