From e99f9deb22b506c98422df9d044671dddfe3d1b1 Mon Sep 17 00:00:00 2001 From: Brett Saviano Date: Mon, 27 Nov 2023 11:43:07 -0500 Subject: [PATCH] Harden `TextSearchProvider` (#1276) --- .../FileSystemProvider/TextSearchProvider.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/providers/FileSystemProvider/TextSearchProvider.ts b/src/providers/FileSystemProvider/TextSearchProvider.ts index 777906f4..5a6717c8 100644 --- a/src/providers/FileSystemProvider/TextSearchProvider.ts +++ b/src/providers/FileSystemProvider/TextSearchProvider.ts @@ -149,8 +149,8 @@ function searchMatchToLine( // This is in the class description line = descLineToDocLine(content, match.attrline, i); break; - } else if (match.attr == "Super") { - // This is a superclass + } else if (match.attr == "Super" || match.attr == "Name") { + // This is in the class definition line if (content[i].includes(match.text)) { line = i; } @@ -306,7 +306,17 @@ export class TextSearchProvider implements vscode.TextSearchProvider { /** Report matches in `file` to the user */ const reportMatchesForFile = async (file: SearchResult): Promise => { - if (token.isCancellationRequested) { + // The last three checks are needed to protect against + // bad output from the server due to a bug. + if ( + // The user cancelled the search + token.isCancellationRequested || + // The server reported no matches in this file + !file.matches.length || + // The file name is malformed + (file.doc.includes("/") && !/\/(?:[^/]+\/)+[^/.]*(?:\.[^/.]+)+/.test(file.doc)) || + (!file.doc.includes("/") && !/(%?[\p{L}\d\u{100}-\u{ffff}]+(?:\.[\p{L}\d\u{100}-\u{ffff}]+)+)/u.test(file.doc)) + ) { return; }