Change behavior of un-terminated HTML comments to be treated as text (fixes #252).

This commit is contained in:
David Anson 2020-03-09 23:06:13 -07:00
parent b87094e33d
commit 4ff6f2f4b1
3 changed files with 17 additions and 5 deletions

View file

@ -96,10 +96,10 @@ const htmlCommentEnd = "-->";
module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) { module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
let i = 0; let i = 0;
while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) { while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) {
let j = text.indexOf(htmlCommentEnd, i); const j = text.indexOf(htmlCommentEnd, i);
if (j === -1) { if (j === -1) {
j = text.length; // Un-terminated comments are treated as text
text += "\\\n"; break;
} }
const comment = text.slice(i + htmlCommentBegin.length, j); const comment = text.slice(i + htmlCommentBegin.length, j);
if ((comment.length > 0) && if ((comment.length > 0) &&

View file

@ -1644,6 +1644,7 @@ tape("clearHtmlCommentTextValid", (test) => {
"-->text", "-->text",
"<!--text--><!--text-->", "<!--text--><!--text-->",
"text<!--text-->text<!--text-->text", "text<!--text-->text<!--text-->text",
"text<!--text > text <!-->text",
"<!--", "<!--",
"text" "text"
]; ];
@ -1680,9 +1681,9 @@ tape("clearHtmlCommentTextValid", (test) => {
"-->text", "-->text",
"<!-- --><!-- -->", "<!-- --><!-- -->",
"text<!-- -->text<!-- -->text", "text<!-- -->text<!-- -->text",
"text<!-- -->text",
"<!--", "<!--",
" \\", "text"
""
]; ];
const actual = helpers.clearHtmlCommentText(validComments.join("\n")); const actual = helpers.clearHtmlCommentText(validComments.join("\n"));
const expected = validResult.join("\n"); const expected = validResult.join("\n");

View file

@ -0,0 +1,11 @@
# Issue 252
```code
```
* List item <!--
```code
```
* List item