Skip to content

Commit 088bea0

Browse files
authored
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
1 parent 503c808 commit 088bea0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/js_lexer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ fn NewLexer_(
642642
lexer.step();
643643

644644
// Handle Windows CRLF
645-
if (lexer.code_point == 'r' and comptime !is_json) {
645+
if (lexer.code_point == '\r' and comptime !is_json) {
646646
lexer.step();
647647
if (lexer.code_point == '\n') {
648648
lexer.step();

test/regression/issue/4893.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { bunEnv, bunExe } from "harness";
2+
import { mkdirSync, rmSync, writeFileSync, readFileSync, mkdtempSync } from "fs";
3+
import { tmpdir } from "os";
4+
import { join } from "path";
5+
6+
it("correctly handles CRLF multiline string in CRLF terminated files", async () => {
7+
const testDir = mkdtempSync(join(tmpdir(), "issue4893-"));
8+
9+
// Clean up from prior runs if necessary
10+
rmSync(testDir, { recursive: true, force: true });
11+
12+
// Create a directory with our test CRLF terminated file
13+
mkdirSync(testDir, { recursive: true });
14+
writeFileSync(join(testDir, "crlf.js"), '"a\\\r\nb"');
15+
16+
const { stdout, exitCode } = Bun.spawnSync({
17+
cmd: [bunExe(), "run", join(testDir, "crlf.js")],
18+
env: bunEnv,
19+
stderr: "inherit",
20+
});
21+
22+
expect(exitCode).toBe(0);
23+
});

0 commit comments

Comments
 (0)