From fe3a5590f542f83ccf5f759857d48572aa7d7ede Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Sat, 21 Dec 2024 22:25:21 +0000 Subject: [PATCH] Escape user code before incorporating in a regex, as part of monarch $Sn rule processing --- src/vs/editor/standalone/common/monarch/monarchCommon.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/standalone/common/monarch/monarchCommon.ts b/src/vs/editor/standalone/common/monarch/monarchCommon.ts index 7137ada8d6a58..bacb4d425acd6 100644 --- a/src/vs/editor/standalone/common/monarch/monarchCommon.ts +++ b/src/vs/editor/standalone/common/monarch/monarchCommon.ts @@ -183,7 +183,7 @@ export function substituteMatches(lexer: ILexerMin, str: string, id: string, mat export function substituteMatchesRe(lexer: ILexerMin, str: string, state: string): string { const re = /\$[sS](\d\d?)/g; let stateMatches: string[] | null = null; - return str.replace(re, function (full, s) { + str = str.replace(re, function (full, s) { if (stateMatches === null) { // split state on demand stateMatches = state.split('.'); stateMatches.unshift(state); @@ -193,6 +193,8 @@ export function substituteMatchesRe(lexer: ILexerMin, str: string, state: string } return ''; }); + + return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&'); } /**