Procházet zdrojové kódy

models/repo_editor: add isRepositoryGitPath to detect invalid file path

Yoginth před 7 roky
rodič
revize
2200186efa
1 změnil soubory, kde provedl 6 přidání a 1 odebrání
  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
 		}