Replace helpers.urlRe with helpers.urlFe to address "innefficient regular expression" CodeQL alert, introduce function expressions as an alternative, test more inputs.

This commit is contained in:
David Anson 2022-12-18 15:46:19 -08:00
parent 485c63c579
commit 8d6e0b5419
5 changed files with 277 additions and 35 deletions

View file

@ -3,7 +3,8 @@
"use strict";
const { addErrorDetailIf, escapeForRegExp, forEachLine, forEachLink,
linkReferenceDefinitionRe, urlRe, withinAnyRange } = require("../helpers");
funcExpExec, linkReferenceDefinitionRe, urlFe, withinAnyRange } =
require("../helpers");
const { codeBlockAndSpanRanges, htmlElementRanges, lineMetadata } =
require("./cache");
@ -27,7 +28,8 @@ module.exports = {
exclusions.push([ lineIndex, 0, line.length ]);
} else {
let match = null;
while ((match = urlRe.exec(line)) !== null) {
while ((match = funcExpExec(urlFe, line)) !== null) {
// @ts-ignore
exclusions.push([ lineIndex, match.index, match[0].length ]);
}
forEachLink(line, (index, _, text, destination) => {