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

@ -2,7 +2,7 @@
"use strict";
const { addErrorContext, filterTokens, urlRe, withinAnyRange } =
const { addErrorContext, filterTokens, funcExpExec, urlFe, withinAnyRange } =
require("../helpers");
const { codeBlockAndSpanRanges, htmlElementRanges, referenceLinkImageData } =
require("./cache");
@ -34,8 +34,9 @@ module.exports = {
while ((match = htmlLinkRe.exec(line)) !== null) {
lineExclusions.push([ lineIndex, match.index, match[0].length ]);
}
while ((match = urlRe.exec(line)) !== null) {
while ((match = funcExpExec(urlFe, line)) !== null) {
const [ bareUrl ] = match;
// @ts-ignore
const matchIndex = match.index;
const bareUrlLength = bareUrl.length;
const prefix = line.slice(0, matchIndex);