diff --git a/.changeset/wicked-mangos-camp.md b/.changeset/wicked-mangos-camp.md new file mode 100644 index 00000000..3bb8d7be --- /dev/null +++ b/.changeset/wicked-mangos-camp.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Fix regression around JS style comments in the body by requiring that they are preceded by a whitespace. diff --git a/src/__tests__/fixtures/comments-within-tag-body/__snapshots__/comments-within-tag-body.expected.txt b/src/__tests__/fixtures/comments-within-tag-body/__snapshots__/comments-within-tag-body.expected.txt index 6e509e61..8e816a74 100644 --- a/src/__tests__/fixtures/comments-within-tag-body/__snapshots__/comments-within-tag-body.expected.txt +++ b/src/__tests__/fixtures/comments-within-tag-body/__snapshots__/comments-within-tag-body.expected.txt @@ -16,9 +16,19 @@ 6╭─ │ │ ╰─ comment.value " and this is a comment " ╰─ ╰─ comment "" -7╭─ - │ │ │ ╰─ closeTagEnd(div) - │ │ ╰─ closeTagName "div" - │ ├─ text "\n" - ╰─ ╰─ closeTagStart " + │ │ │ ╰─ closeTagEnd(div) + │ │ ╰─ closeTagName "div" + ╰─ ╰─ closeTagStart " + But this, this is not a http://comment.com + And yet this is a //comment + And also /* this is a comment */ + Because a//comment must be preceded by whitespace. diff --git a/src/states/HTML_CONTENT.ts b/src/states/HTML_CONTENT.ts index a982d41e..6af0faee 100644 --- a/src/states/HTML_CONTENT.ts +++ b/src/states/HTML_CONTENT.ts @@ -94,7 +94,10 @@ export const HTML_CONTENT: StateDefinition = { this.endText(); this.enterState(STATE.INLINE_SCRIPT); this.pos++; // skip space - } else if (code === CODE.FORWARD_SLASH) { + } else if ( + code === CODE.FORWARD_SLASH && + isWhitespaceCode(this.lookAtCharCodeAhead(-1)) + ) { // Check next character to see if we are in a comment switch (this.lookAtCharCodeAhead(1)) { case CODE.FORWARD_SLASH: