Parcourir la source

models/repo_editor: add isRepositoryGitPath to detect invalid file path

Yoginth il y a 7 ans
Parent
commit
2200186efa
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      models/repo_editor.go

+ 6 - 1
models/repo_editor.go

@@ -435,6 +435,11 @@ type UploadRepoFileOptions struct {
 	Files        []string // In UUID format
 }
 
+// isRepositoryGitPath returns true if given path is or resides inside ".git" path of the repository.
+func isRepositoryGitPath(path string) bool {
+	return strings.HasSuffix(path, ".git") || strings.Contains(path, ".git"+string(os.PathSeparator))
+}
+
 // UploadRepoFiles uploads files to a repository
 func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) (err error) {
 	if len(opts.Files) == 0 {
@@ -473,7 +478,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 		}
 
 		// Prevent copying files into .git directory
-		if strings.HasPrefix(upload.Name, ".git/") {
+		if isRepositoryGitPath(upload.Name) {
 			continue
 		}