Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to merge if file path contains " or \ #8629

Merged
merged 9 commits into from
Nov 1, 2019
Merged
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(`([*[?! ])`)
zeripath marked this conversation as resolved.
Show resolved Hide resolved

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)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
Expand Down