Simplify stripBackslash

This commit is contained in:
David Dworken 2023-02-14 08:47:38 -08:00
parent 4b5b729328
commit 2ae54ef74e
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View File

@ -1274,13 +1274,11 @@ func containsUnescaped(query string, token string) bool {
}
func stripBackslash(query string) string {
runeQuery := []rune(query)
var newQuery []rune
for i := 0; i < len(runeQuery); i++ {
if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
i++
for _, char := range query {
if char != '\\' {
newQuery = append(newQuery, char)
}
newQuery = append(newQuery, runeQuery[i])
}
return string(newQuery)
}

View File

@ -489,6 +489,9 @@ func TestStripBackslash(t *testing.T) {
{"f \\bar", "f bar"},
{"f\\:bar", "f:bar"},
{"f\\:bar\\", "f:bar"},
{"\\f\\:bar\\", "f:bar"},
{"", ""},
{"\\\\", ""},
}
for _, tc := range testcases {
actual := stripBackslash(tc.input)