mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update definition of helpers.isBlankLine to treat unterminated start/end comments as potentially blank lines (fixes #431).
This commit is contained in:
parent
1b23976aa2
commit
6dea67825a
4 changed files with 67 additions and 11 deletions
|
@ -77,12 +77,18 @@ module.exports.isObject = function isObject(obj) {
|
|||
return (obj !== null) && (typeof obj === "object") && !Array.isArray(obj);
|
||||
};
|
||||
// Returns true iff the input line is blank (no content)
|
||||
// Example: Contains nothing, whitespace, or comments
|
||||
var blankLineRe = />|(?:<!--.*?-->)/g;
|
||||
// Example: Contains nothing, whitespace, or comment (unclosed start/end okay)
|
||||
module.exports.isBlankLine = function isBlankLine(line) {
|
||||
// Call to String.replace follows best practices and is not a security check
|
||||
// False-positive for js/incomplete-multi-character-sanitization
|
||||
return !line || !line.trim() || !line.replace(blankLineRe, "").trim();
|
||||
return (!line ||
|
||||
!line.trim() ||
|
||||
!line
|
||||
.replace(/<!--.*?-->/g, "")
|
||||
.replace(/<!--.*$/g, "")
|
||||
.replace(/^.*-->/g, "")
|
||||
.replace(/>/g, "")
|
||||
.trim());
|
||||
};
|
||||
/**
|
||||
* Compare function for Array.prototype.sort for ascending order of numbers.
|
||||
|
|
|
@ -63,12 +63,20 @@ module.exports.isObject = function isObject(obj) {
|
|||
};
|
||||
|
||||
// Returns true iff the input line is blank (no content)
|
||||
// Example: Contains nothing, whitespace, or comments
|
||||
const blankLineRe = />|(?:<!--.*?-->)/g;
|
||||
// Example: Contains nothing, whitespace, or comment (unclosed start/end okay)
|
||||
module.exports.isBlankLine = function isBlankLine(line) {
|
||||
// Call to String.replace follows best practices and is not a security check
|
||||
// False-positive for js/incomplete-multi-character-sanitization
|
||||
return !line || !line.trim() || !line.replace(blankLineRe, "").trim();
|
||||
return (
|
||||
!line ||
|
||||
!line.trim() ||
|
||||
!line
|
||||
.replace(/<!--.*?-->/g, "")
|
||||
.replace(/<!--.*$/g, "")
|
||||
.replace(/^.*-->/g, "")
|
||||
.replace(/>/g, "")
|
||||
.trim()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
38
test/lists-with-commented-items.md
Normal file
38
test/lists-with-commented-items.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Lists with Commented Items
|
||||
|
||||
Text
|
||||
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
<!--
|
||||
- commented subitem: description
|
||||
- commented subitem: description
|
||||
-->
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
|
||||
Text
|
||||
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
<!-- - commented subitem: description
|
||||
- commented subitem: description -->
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
|
||||
Text
|
||||
|
||||
- item <!-- comment -->
|
||||
<!-- - commented subitem: description -->
|
||||
- item <!-- comment -->
|
||||
|
||||
Text
|
||||
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
<!-- - commented subitem: description -->
|
||||
<!-- - commented subitem: description -->
|
||||
- item <!-- comment -->
|
||||
- item <!-- comment -->
|
||||
|
||||
Text
|
|
@ -226,7 +226,7 @@ bar`
|
|||
});
|
||||
|
||||
test("isBlankLine", (t) => {
|
||||
t.plan(25);
|
||||
t.plan(29);
|
||||
const blankLines = [
|
||||
null,
|
||||
"",
|
||||
|
@ -244,7 +244,11 @@ test("isBlankLine", (t) => {
|
|||
"> ",
|
||||
"> > > \t",
|
||||
"> <!--text-->",
|
||||
">><!--text-->"
|
||||
">><!--text-->",
|
||||
"<!--",
|
||||
" <!-- text",
|
||||
"text --> ",
|
||||
"-->"
|
||||
];
|
||||
blankLines.forEach((line) => t.true(helpers.isBlankLine(line), line || ""));
|
||||
const nonBlankLines = [
|
||||
|
@ -253,9 +257,9 @@ test("isBlankLine", (t) => {
|
|||
".",
|
||||
"> .",
|
||||
"<!--text--> text",
|
||||
"<!--->",
|
||||
"<!--",
|
||||
"-->"
|
||||
"text <!--text-->",
|
||||
"text <!--",
|
||||
"--> text"
|
||||
];
|
||||
nonBlankLines.forEach((line) => t.true(!helpers.isBlankLine(line), line));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue