Skip to content

Commit

Permalink
Harden TextSearchProvider (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano authored Nov 27, 2023
1 parent 594b547 commit e99f9de
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/providers/FileSystemProvider/TextSearchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -306,7 +306,17 @@ export class TextSearchProvider implements vscode.TextSearchProvider {

/** Report matches in `file` to the user */
const reportMatchesForFile = async (file: SearchResult): Promise<void> => {
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;
}

Expand Down

0 comments on commit e99f9de

Please sign in to comment.