Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require a whitespace before js style comments inside html content #127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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