Skip to content

Commit

Permalink
fix: require a whitespace before js style comments inside html content (
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Aug 2, 2022
1 parent 89fe2c7 commit 222b145
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-mangos-camp.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@
6╭─ <!-- and this is a comment -->
│ │ ╰─ comment.value " and this is a comment "
╰─ ╰─ comment "<!-- and this is a comment -->"
7╭─ </div>
│ │ │ ╰─ closeTagEnd(div)
│ │ ╰─ closeTagName "div"
│ ├─ text "\n"
╰─ ╰─ closeTagStart "</"
8╰─
7╭─ But this, this is not a http://comment.com
╰─ ╰─ text "\n But this, this is not a http://comment.com\n And yet this is a "
8╭─ And yet this is a //comment
│ │ ╰─ comment.value "comment"
╰─ ╰─ comment "//comment"
9╭─ And also /* this is a comment */
│ │ │ ╰─ comment.value " this is a comment "
│ │ ╰─ comment "/* this is a comment */"
╰─ ╰─ text "\n And also "
10╭─ Because a//comment must be preceded by whitespace.
╰─ ╰─ text "\n Because a//comment must be preceded by whitespace.\n"
11╭─ </div>
│ │ │ ╰─ closeTagEnd(div)
│ │ ╰─ closeTagName "div"
╰─ ╰─ closeTagStart "</"
12╰─
4 changes: 4 additions & 0 deletions src/__tests__/fixtures/comments-within-tag-body/input.marko
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
/* But this is a comment */
And this is more text
<!-- and this is a comment -->
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.
</div>
5 changes: 4 additions & 1 deletion src/states/HTML_CONTENT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const HTML_CONTENT: StateDefinition<HTMLContentMeta> = {
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:
Expand Down

0 comments on commit 222b145

Please sign in to comment.