Skip to content

Commit

Permalink
fix: issue with escaped placeholder at end of tag (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Dec 7, 2022
1 parent 76d00ee commit 635b97c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-monkeys-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fix issue where and extra character was being consumed if an escaped placeholder was at the end of a tag.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@
│ │ │╰─ closeTagEnd(d)
│ │ ╰─ closeTagName
│ ├─ text "\n"
╰─ ╰─ closeTagStart "</"
╰─ ╰─ closeTagStart "</"
16├─
17╭─ <e>\${</e>
│ │││ │ │ │╰─ closeTagEnd(e)
│ │││ │ │ ╰─ closeTagName
│ │││ │ ╰─ closeTagStart "</"
│ │││ ╰─ text "${"
│ ││╰─ openTagEnd
│ │╰─ tagName
╰─ ╰─ openTagStart
18╰─
4 changes: 3 additions & 1 deletion src/__tests__/fixtures/placeholder-backslash/input.marko
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
</c>
<d>
\\$!{test}
</d>
</d>

<e>\${</e>
3 changes: 2 additions & 1 deletion src/states/PLACEHOLDER.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export function checkForPlaceholder(parser: Parser, code: number) {
}

if (curCode === CODE.OPEN_CURLY_BRACE) {
parser.forward = 0;

if (ahead) {
const remainder = ahead % 2;
const extra = (ahead + remainder) / 2; // Number of backslashes to omit from output.
Expand All @@ -94,7 +96,6 @@ export function checkForPlaceholder(parser: Parser, code: number) {
parser.endText();
parser.enterState(PLACEHOLDER).escape = escape;
parser.pos += escape ? 2 : 3; // skip ${ or $!{
parser.forward = 0;
parser.enterState(STATE.EXPRESSION).shouldTerminate =
matchesCloseCurlyBrace;
return true;
Expand Down

0 comments on commit 635b97c

Please sign in to comment.