Преглед на файлове

models/repo_editor: add isRepositoryGitPath to detect invalid file path

Yoginth преди 7 години
родител
ревизия
2200186efa
променени са 1 файла, в които са добавени 6 реда и са изтрити 1 реда
  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
 		}