Skip to content

Commit

Permalink
fix: issue parsing expressions with unenclosed newlines in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed May 9, 2022
1 parent 469b4bc commit a4e3635
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-comics-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fixes issue where expressions could consume an extra character when windows line endings used.
2 changes: 2 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ for (const entry of fs.readdirSync(FIXTURES)) {
const dir = path.join(FIXTURES, entry);
const filename = path.join(dir, "input.marko");
const src = await fs.promises.readFile(filename, "utf-8");
// Use this if you want to psuedo test on windows locally.
// const src = (await fs.promises.readFile(filename, "utf-8")).replace(/\n/g, "\r\n");
const lines = getLines(src);
const partsByLine: {
range: Range;
Expand Down
7 changes: 5 additions & 2 deletions src/states/EXPRESSION.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,14 @@ function checkForOperators(parser: Parser, expression: ExpressionMeta) {
if (match.length === 0) {
// We matched a look behind.
parser.consumeWhitespace();
parser.pos--;
} else {
// We matched a look ahead.
parser.pos += match.length - 1;
parser.pos += match.length;
}

// After this point we should be on the character we want to process next
// so we don't want to move forward and miss that character.
parser.forward = 0;
} else {
return false;
}
Expand Down

0 comments on commit a4e3635

Please sign in to comment.