Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions services/pull/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -374,6 +375,8 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
return nil
}

var escapedSymbols = regexp.MustCompile(`([*[?! ])`)

func getDiffTree(repoPath, baseBranch, headBranch string) (string, error) {
getDiffTreeFromBranch := func(repoPath, baseBranch, headBranch string) (string, error) {
var outbuf, errbuf strings.Builder
Expand Down Expand Up @@ -409,14 +412,10 @@ func getDiffTree(repoPath, baseBranch, headBranch string) (string, error) {
for scanner.Scan() {
filepath := scanner.Text()

// escape '\', '*', '?', '[', spaces and '!' prefix
// replace '\' first
filepath = strings.ReplaceAll(filepath, `\`, `\\`)
filepath = strings.ReplaceAll(filepath, "*", `\*`)
filepath = strings.ReplaceAll(filepath, "?", `\?`)
filepath = strings.ReplaceAll(filepath, "[", `\[`)
filepath = strings.ReplaceAll(filepath, " ", `\ `)
filepath = strings.ReplaceAll(filepath, "!", `\!`)
// escape '*', '?', '[', spaces and '!' prefix
filepath = escapedSymbols.ReplaceAllString(filepath, `\$1`)

// no necessary to escape the first '#' symbol because the first symbol is '/'
fmt.Fprintf(&out, "/%s\n", filepath)
Expand Down