From 7be4b2c6977c9d81006ac1fe080321247d025371 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Dec 2024 12:56:20 -0800 Subject: [PATCH] Harden `sanitizeLog` against incorrect matches on TypeScript versions. (#60794) Co-authored-by: Andrew Branch --- src/harness/tsserverLogger.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/harness/tsserverLogger.ts b/src/harness/tsserverLogger.ts index 1ac20125b8df0..5eceaff711711 100644 --- a/src/harness/tsserverLogger.ts +++ b/src/harness/tsserverLogger.ts @@ -111,7 +111,7 @@ export function sanitizeLog(s: string): string { s = s.replace(/Elapsed::?\s*\d+(?:\.\d+)?ms/g, "Elapsed:: *ms"); s = s.replace(/"updateGraphDurationMs":\s*\d+(?:\.\d+)?/g, `"updateGraphDurationMs": *`); s = s.replace(/"createAutoImportProviderProgramDurationMs":\s*\d+(?:\.\d+)?/g, `"createAutoImportProviderProgramDurationMs": *`); - s = replaceAll(s, ts.version, "FakeVersion"); + s = s.replace(new RegExp(`\\b${ts.regExpEscape(ts.version)}\\b`, "g"), "FakeVersion"); s = s.replace(/getCompletionData: Get current token: \d+(?:\.\d+)?/g, `getCompletionData: Get current token: *`); s = s.replace(/getCompletionData: Is inside comment: \d+(?:\.\d+)?/g, `getCompletionData: Is inside comment: *`); s = s.replace(/getCompletionData: Get previous token: \d+(?:\.\d+)?/g, `getCompletionData: Get previous token: *`); @@ -130,7 +130,8 @@ export function sanitizeLog(s: string): string { s = s.replace(/"semanticDiag":\s*\d+(?:.\d+)?/g, `"semanticDiag": *`); s = s.replace(/"suggestionDiag":\s*\d+(?:.\d+)?/g, `"suggestionDiag": *`); s = s.replace(/"regionSemanticDiag":\s*\d+(?:.\d+)?/g, `"regionSemanticDiag": *`); - s = replaceAll(s, `@ts${ts.versionMajorMinor}`, `@tsFakeMajor.Minor`); + s = s.replace(new RegExp(`\\b@ts${ts.regExpEscape(ts.versionMajorMinor)}\\b`, "g"), `@tsFakeMajor.Minor`); + s = sanitizeHarnessLSException(s); return s; }