261
262
export function extractVulnerabilitiesFromText(text: string): { newText: string; vulnerabilities: IMarkdownVulnerability[] } {
263
>
const vulnerabilities: IMarkdownVulnerability[] = [];
annotations.ts
264
>
let newText = text;
265
>
let match: RegExpExecArray | null;
266
>
while ((match = /<vscode_annotation details='(.*?)'>(.*?)<\/vscode_annotation>/ms.exec(newText)) !== null) {
267
>
const [full, details, content] = match;
268
>
const start = match.index;
269
>
const textBefore = newText.substring(0, start);
270
>
const linesBefore = textBefore.split('\n').length - 1;
271
>
const linesInside = content.split('\n').length - 1;
272
>
273
>
const previousNewlineIdx = textBefore.lastIndexOf('\n');
274
>
const startColumn = start - (previousNewlineIdx + 1) + 1;
275
>
const endPreviousNewlineIdx = (textBefore + content).lastIndexOf('\n');
276
>
const endColumn = start + content.length - (endPreviousNewlineIdx + 1) + 1;
277
>
278
>
try {
279
>
const vulnDetails: IChatAgentVulnerabilityDetails[] = JSON.parse(decodeURIComponent(details));
280
>
vulnDetails.forEach(({ title, description }) => vulnerabilities.push({
281
>
title, description, range: { startLineNumber: linesBefore + 1, startColumn, endLineNumber: linesBefore + linesInside + 1, endColumn }
282
>
}));
283
>
} catch (err) {
284
// Something went wrong with encoding this text, just ignore it
285
}
286
>
newText = newText.substring(0, start) + content + newText.substring(start + full.length);
annotations.ts
287
>
}
288
>
289
>
return { newText, vulnerabilities };
290
>
}