aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mordy Tikotzky <mordytk@gmail.com> 2023-09-14 00:05:02 -0400
committerGravatar GitHub <noreply@github.com> 2023-09-13 21:05:02 -0700
commit088bea026e6c49389f51ef6979c5e2d6dfd6d353 (patch)
tree0c9919ea8bb734a1175d114f1af710e7700923ff
parent503c80892980bd60dc2205a63832e52be6b4478f (diff)
downloadbun-088bea026e6c49389f51ef6979c5e2d6dfd6d353.tar.gz
bun-088bea026e6c49389f51ef6979c5e2d6dfd6d353.tar.zst
bun-088bea026e6c49389f51ef6979c5e2d6dfd6d353.zip
Fix bug with multiline string in CRLF terminated files (#4893) (#5318)
* Fix bug with multiline string in CRLF terminated files (#4893) * add test for #4893
-rw-r--r--src/js_lexer.zig2
-rw-r--r--test/regression/issue/4893.test.ts23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index 01852bb65..47b6fdcb9 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -642,7 +642,7 @@ fn NewLexer_(
lexer.step();
// Handle Windows CRLF
- if (lexer.code_point == 'r' and comptime !is_json) {
+ if (lexer.code_point == '\r' and comptime !is_json) {
lexer.step();
if (lexer.code_point == '\n') {
lexer.step();
diff --git a/test/regression/issue/4893.test.ts b/test/regression/issue/4893.test.ts
new file mode 100644
index 000000000..43850693b
--- /dev/null
+++ b/test/regression/issue/4893.test.ts
@@ -0,0 +1,23 @@
+import { bunEnv, bunExe } from "harness";
+import { mkdirSync, rmSync, writeFileSync, readFileSync, mkdtempSync } from "fs";
+import { tmpdir } from "os";
+import { join } from "path";
+
+it("correctly handles CRLF multiline string in CRLF terminated files", async () => {
+ const testDir = mkdtempSync(join(tmpdir(), "issue4893-"));
+
+ // Clean up from prior runs if necessary
+ rmSync(testDir, { recursive: true, force: true });
+
+ // Create a directory with our test CRLF terminated file
+ mkdirSync(testDir, { recursive: true });
+ writeFileSync(join(testDir, "crlf.js"), '"a\\\r\nb"');
+
+ const { stdout, exitCode } = Bun.spawnSync({
+ cmd: [bunExe(), "run", join(testDir, "crlf.js")],
+ env: bunEnv,
+ stderr: "inherit",
+ });
+
+ expect(exitCode).toBe(0);
+});