[search addon] Escape sequence only for \n, \r, \t and \\

When `\` is followed by any other character, it will not be
interpreted as an escape sequence, i.e. `\3` will be
interpreted as literal `\3`, not as `3`.

Fixes https://github.com/codemirror/CodeMirror/issues/5428
This commit is contained in:
Raymond Hill 2019-07-07 11:44:10 -04:00 committed by Marijn Haverbeke
parent f454d5784b
commit ae07cb1776
1 changed files with 4 additions and 2 deletions

View File

@ -78,10 +78,12 @@
}
function parseString(string) {
return string.replace(/\\(.)/g, function(_, ch) {
return string.replace(/\\([nrt\\])/g, function(match, ch) {
if (ch == "n") return "\n"
if (ch == "r") return "\r"
return ch
if (ch == "t") return "\t"
if (ch == "\\") return "\\"
return match
})
}