Skip to content

Commit

Permalink
Don't unescape backslash codes in replaced content
Browse files Browse the repository at this point in the history
FIX: Fix a bug that caused codes like `\n` to be unescaped in strings
inserted via replace placeholders like `$&`.

Closes codemirror/dev#1291
  • Loading branch information
marijnh committed Nov 7, 2023
1 parent 7a4a57e commit 8491f3d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ class RegExpQuery extends QueryType<RegExpResult> {
}

getReplacement(result: RegExpResult) {
return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g, (m, i) =>
return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) =>
i == "$" ? "$"
: i == "&" ? result.match[0]
: i != "0" && +i < result.match.length ? result.match[i]
: m))
: m)
}

matchAll(state: EditorState, limit: number) {
Expand Down

0 comments on commit 8491f3d

Please sign in to comment.