Fix MD011/no-reversed-links to better handle escaped RegExp content in reversed links.

This commit is contained in:
David Anson 2019-09-28 14:30:16 -07:00
parent 40ac584482
commit 6587ba7261
2 changed files with 13 additions and 2 deletions

View file

@ -2,7 +2,8 @@
"use strict"; "use strict";
const { addError, forEachInlineChild } = require("../helpers"); const { addError, forEachInlineChild, unescapeMarkdown } =
require("../helpers");
const reversedLinkRe = /\(([^)]+)\)\[([^\]^][^\]]*)]/g; const reversedLinkRe = /\(([^)]+)\)\[([^\]^][^\]]*)]/g;
@ -17,7 +18,7 @@ module.exports = {
while ((match = reversedLinkRe.exec(content)) !== null) { while ((match = reversedLinkRe.exec(content)) !== null) {
const [ reversedLink, linkText, linkDestination ] = match; const [ reversedLink, linkText, linkDestination ] = match;
const line = params.lines[lineNumber - 1]; const line = params.lines[lineNumber - 1];
const column = line.indexOf(reversedLink) + 1; const column = unescapeMarkdown(line).indexOf(reversedLink) + 1;
const length = reversedLink.length; const length = reversedLink.length;
addError( addError(
onError, onError,

View file

@ -22,3 +22,13 @@ code code
code` text code` text
text text
text (reversed)[link] text {MD011} text (reversed)[link] text {MD011}
## Escaped JavaScript Content
var IDENT_RE = '([a-zA-Z]|\\.[a-zA-Z.])[a-zA-Z0-9._]*'; {MD011}
begin: /\B(([\/.])[\w\-.\/=]+)+/, {MD011}
{begin: '%r\\(', end: '\\)[a-z]*'} {MD011}
return /(?:(?:(^|\/)[!.])|[*?+()|\[\]{}]|[+@]\()/.test(str); {MD011}