Skip to content

Commit

Permalink
Harden TextSearchProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Nov 27, 2023
1 parent 594b547 commit 51f55b4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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,9 +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) {
return;
}
// 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;

Check failure on line 319 in src/providers/FileSystemProvider/TextSearchProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Insert `⏎·······`

const uri = DocumentContentProvider.getUri(file.doc, "", "", true, options.folder);
const content = decoder.decode(await vscode.workspace.fs.readFile(uri)).split("\n");
Expand Down

0 comments on commit 51f55b4

Please sign in to comment.