Update definition of helpers.isBlankLine to treat unterminated start/end comments as potentially blank lines (fixes #431).

This commit is contained in:
David Anson 2021-12-20 04:18:45 +00:00 committed by GitHub
parent 1b23976aa2
commit 6dea67825a
4 changed files with 67 additions and 11 deletions

View file

@ -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.