Skip to content

Commit

Permalink
Allow escaped linebreaks in buildozer command arguments (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmos authored Feb 4, 2020
1 parent f630fda commit 9e63c6f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions edit/buildozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,18 @@ func checkCommandUsage(name string, cmd CommandInfo, count int) {
os.Exit(1)
}

// Match text that only contains spaces if they're escaped with '\'.
var spaceRegex = regexp.MustCompile(`(\\ |[^ \n])+`)
// Match text that only contains spaces or line breaks if they're escaped with '\'.
var spaceRegex = regexp.MustCompile(`(\\ |\\\n|[^ \n])+`)

// SplitOnSpaces behaves like strings.Fields, except that spaces can be escaped.
// Also splits on linebreaks unless they are escaped too.
// " some dummy\\ string" -> ["some", "dummy string"]
func SplitOnSpaces(input string) []string {
result := spaceRegex.FindAllString(input, -1)
for i, s := range result {
result[i] = strings.Replace(s, `\ `, " ", -1)
s = strings.Replace(s, `\ `, " ", -1)
s = strings.Replace(s, "\\\n", "\n", -1)
result[i] = s
}
return result
}
Expand Down

0 comments on commit 9e63c6f

Please sign in to comment.