mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update helpers.inlineCommentRe to fix an instance of "Polynomial regular expression used on uncontrolled data".
This commit is contained in:
parent
1c89dd5776
commit
f46ee0732f
3 changed files with 32 additions and 24 deletions
|
|
@ -38,11 +38,11 @@ module.exports.newLineRe = newLineRe;
|
||||||
module.exports.frontMatterRe =
|
module.exports.frontMatterRe =
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m;
|
/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m;
|
||||||
// Regular expression for matching inline disable/enable comments
|
// Regular expression for matching the start of inline disable/enable comments
|
||||||
var inlineCommentRe =
|
var inlineCommentStartRe =
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/<!--\s*markdownlint-(?:(?:(disable|enable|capture|restore|disable-file|enable-file|disable-next-line)((?:\s+[a-z0-9_-]+)*))|(?:(configure-file)\s+([\s\S]*?)))\s*-->/ig;
|
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-next-line|configure-file))(?:\s|-->)/ig;
|
||||||
module.exports.inlineCommentRe = inlineCommentRe;
|
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
||||||
// Regular expressions for range matching
|
// Regular expressions for range matching
|
||||||
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig;
|
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig;
|
||||||
module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
|
module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
|
||||||
|
|
@ -176,9 +176,9 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
var inlineCommentIndex = text
|
var inlineCommentIndex = text
|
||||||
.slice(i, j + htmlCommentEnd.length)
|
.slice(i, j + htmlCommentEnd.length)
|
||||||
.search(inlineCommentRe);
|
.search(inlineCommentStartRe);
|
||||||
// If not a markdownlint inline directive...
|
// If not a markdownlint inline directive...
|
||||||
if (inlineCommentIndex === -1) {
|
if (inlineCommentIndex !== 0) {
|
||||||
text =
|
text =
|
||||||
text.slice(0, i + htmlCommentBegin.length) +
|
text.slice(0, i + htmlCommentBegin.length) +
|
||||||
content.replace(/[^\r\n]/g, ".") +
|
content.replace(/[^\r\n]/g, ".") +
|
||||||
|
|
@ -1303,9 +1303,14 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin
|
||||||
input.forEach(function (line, lineIndex) {
|
input.forEach(function (line, lineIndex) {
|
||||||
if (!noInlineConfig) {
|
if (!noInlineConfig) {
|
||||||
var match = null;
|
var match = null;
|
||||||
while ((match = helpers.inlineCommentRe.exec(line))) {
|
while ((match = helpers.inlineCommentStartRe.exec(line))) {
|
||||||
var action = (match[1] || match[3]).toUpperCase();
|
var action = match[2].toUpperCase();
|
||||||
var parameter = match[2] || match[4];
|
var startIndex = match.index + match[1].length;
|
||||||
|
var endIndex = line.indexOf("-->", startIndex);
|
||||||
|
if (endIndex === -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var parameter = line.slice(startIndex, endIndex);
|
||||||
forEachMatch(action, parameter, lineIndex + 1);
|
forEachMatch(action, parameter, lineIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1330,9 +1335,8 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin
|
||||||
function applyEnableDisable(action, parameter, state) {
|
function applyEnableDisable(action, parameter, state) {
|
||||||
state = __assign({}, state);
|
state = __assign({}, state);
|
||||||
var enabled = (action.startsWith("ENABLE"));
|
var enabled = (action.startsWith("ENABLE"));
|
||||||
var items = parameter ?
|
var trimmed = parameter && parameter.trim();
|
||||||
parameter.trim().toUpperCase().split(/\s+/) :
|
var items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames;
|
||||||
allRuleNames;
|
|
||||||
items.forEach(function (nameUpper) {
|
items.forEach(function (nameUpper) {
|
||||||
(aliasToRuleNames[nameUpper] || []).forEach(function (ruleName) {
|
(aliasToRuleNames[nameUpper] || []).forEach(function (ruleName) {
|
||||||
state[ruleName] = enabled;
|
state[ruleName] = enabled;
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ module.exports.frontMatterRe =
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m;
|
/((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m;
|
||||||
|
|
||||||
// Regular expression for matching inline disable/enable comments
|
// Regular expression for matching the start of inline disable/enable comments
|
||||||
const inlineCommentRe =
|
const inlineCommentStartRe =
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/<!--\s*markdownlint-(?:(?:(disable|enable|capture|restore|disable-file|enable-file|disable-next-line)((?:\s+[a-z0-9_-]+)*))|(?:(configure-file)\s+([\s\S]*?)))\s*-->/ig;
|
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-next-line|configure-file))(?:\s|-->)/ig;
|
||||||
module.exports.inlineCommentRe = inlineCommentRe;
|
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
||||||
|
|
||||||
// Regular expressions for range matching
|
// Regular expressions for range matching
|
||||||
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig;
|
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig;
|
||||||
|
|
@ -163,9 +163,9 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
const inlineCommentIndex = text
|
const inlineCommentIndex = text
|
||||||
.slice(i, j + htmlCommentEnd.length)
|
.slice(i, j + htmlCommentEnd.length)
|
||||||
.search(inlineCommentRe);
|
.search(inlineCommentStartRe);
|
||||||
// If not a markdownlint inline directive...
|
// If not a markdownlint inline directive...
|
||||||
if (inlineCommentIndex === -1) {
|
if (inlineCommentIndex !== 0) {
|
||||||
text =
|
text =
|
||||||
text.slice(0, i + htmlCommentBegin.length) +
|
text.slice(0, i + htmlCommentBegin.length) +
|
||||||
content.replace(/[^\r\n]/g, ".") +
|
content.replace(/[^\r\n]/g, ".") +
|
||||||
|
|
|
||||||
|
|
@ -346,9 +346,14 @@ function getEnabledRulesPerLineNumber(
|
||||||
input.forEach((line, lineIndex) => {
|
input.forEach((line, lineIndex) => {
|
||||||
if (!noInlineConfig) {
|
if (!noInlineConfig) {
|
||||||
let match = null;
|
let match = null;
|
||||||
while ((match = helpers.inlineCommentRe.exec(line))) {
|
while ((match = helpers.inlineCommentStartRe.exec(line))) {
|
||||||
const action = (match[1] || match[3]).toUpperCase();
|
const action = match[2].toUpperCase();
|
||||||
const parameter = match[2] || match[4];
|
const startIndex = match.index + match[1].length;
|
||||||
|
const endIndex = line.indexOf("-->", startIndex);
|
||||||
|
if (endIndex === -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const parameter = line.slice(startIndex, endIndex);
|
||||||
forEachMatch(action, parameter, lineIndex + 1);
|
forEachMatch(action, parameter, lineIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -375,9 +380,8 @@ function getEnabledRulesPerLineNumber(
|
||||||
function applyEnableDisable(action, parameter, state) {
|
function applyEnableDisable(action, parameter, state) {
|
||||||
state = { ...state };
|
state = { ...state };
|
||||||
const enabled = (action.startsWith("ENABLE"));
|
const enabled = (action.startsWith("ENABLE"));
|
||||||
const items = parameter ?
|
const trimmed = parameter && parameter.trim();
|
||||||
parameter.trim().toUpperCase().split(/\s+/) :
|
const items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames;
|
||||||
allRuleNames;
|
|
||||||
items.forEach((nameUpper) => {
|
items.forEach((nameUpper) => {
|
||||||
(aliasToRuleNames[nameUpper] || []).forEach((ruleName) => {
|
(aliasToRuleNames[nameUpper] || []).forEach((ruleName) => {
|
||||||
state[ruleName] = enabled;
|
state[ruleName] = enabled;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue