Skip to content

Commit

Permalink
Fix issue with MD044/proper-names where stateful RegExp could fail to…
Browse files Browse the repository at this point in the history
… match bare URLs, remove unnecessary use of bareUrlRe by MD033/no-inline-html.
  • Loading branch information
DavidAnson committed Oct 25, 2019
1 parent 57c6617 commit 31ffe52
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/md033.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

"use strict";

const { addError, bareUrlRe, forEachLine, unescapeMarkdown } =
require("../helpers");
const { addError, forEachLine, unescapeMarkdown } = require("../helpers");
const { lineMetadata } = require("./cache");

const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
Expand All @@ -24,10 +23,10 @@ module.exports = {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
let match = null;
// eslint-disable-next-line no-unmodified-loop-condition
while (!inCode && (match = htmlElementRe.exec(line))) {
while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) {
const [ tag, content, element ] = match;
if (!allowedElements.includes(element.toLowerCase()) &&
!tag.endsWith("\\>") && !bareUrlRe.test(content) &&
!tag.endsWith("\\>") &&
!emailAddressRe.test(content)) {
const prefix = line.substring(0, match.index);
if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/md044.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
let match = null;
while ((match = anyNameRe.exec(line)) !== null) {
const fullMatch = match[0];
if (!bareUrlRe.test(fullMatch)) {
if (fullMatch.search(bareUrlRe) === -1) {
const wordMatch = fullMatch
.replace(/^\W*/, "").replace(/\W*$/, "");
if (!names.includes(wordMatch)) {
Expand Down
14 changes: 14 additions & 0 deletions test/proper-names-urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default": true,
"proper-names": {
"names": [
"HTTPS",
"EXAMPLE",
"COM",
"DIRECTORY",
"FILE"
]
},
"no-bare-urls": false,
"code-block-style": false
}
33 changes: 33 additions & 0 deletions test/proper-names-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Proper Names in URLs

Text https text {MD044}
Text example text {MD044}
Text com text {MD044}
Text directory text {MD044}
Text file text {MD044}
Text HTTPS EXAMPLE COM DIRECTORY FILE text

> The following lines are deliberately duplicated
Text https://example.com/directory/file text

Text https://example.com/directory/file text

Text <https://example.com/directory/file> text

Text <https://example.com/directory/file> text

Text [https://example.com/directory/file](https://example.com/directory/file) text

Text [https://example.com/directory/file](https://example.com/directory/file) text

Text `https://example.com/directory/file` text
Text `https://example.com/directory/file` text

```text
Text https://example.com/directory/file text
Text https://example.com/directory/file text
```

Text https://example.com/directory/file text
Text https://example.com/directory/file text

0 comments on commit 31ffe52

Please sign in to comment.