Skip to content

Commit e99f9de

Browse files
authored
Harden TextSearchProvider (#1276)
1 parent 594b547 commit e99f9de

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/providers/FileSystemProvider/TextSearchProvider.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function searchMatchToLine(
149149
// This is in the class description
150150
line = descLineToDocLine(content, match.attrline, i);
151151
break;
152-
} else if (match.attr == "Super") {
153-
// This is a superclass
152+
} else if (match.attr == "Super" || match.attr == "Name") {
153+
// This is in the class definition line
154154
if (content[i].includes(match.text)) {
155155
line = i;
156156
}
@@ -306,7 +306,17 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
306306

307307
/** Report matches in `file` to the user */
308308
const reportMatchesForFile = async (file: SearchResult): Promise<void> => {
309-
if (token.isCancellationRequested) {
309+
// The last three checks are needed to protect against
310+
// bad output from the server due to a bug.
311+
if (
312+
// The user cancelled the search
313+
token.isCancellationRequested ||
314+
// The server reported no matches in this file
315+
!file.matches.length ||
316+
// The file name is malformed
317+
(file.doc.includes("/") && !/\/(?:[^/]+\/)+[^/.]*(?:\.[^/.]+)+/.test(file.doc)) ||
318+
(!file.doc.includes("/") && !/(%?[\p{L}\d\u{100}-\u{ffff}]+(?:\.[\p{L}\d\u{100}-\u{ffff}]+)+)/u.test(file.doc))
319+
) {
310320
return;
311321
}
312322

0 commit comments

Comments
 (0)