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
This commit is contained in:
Mordy Tikotzky
2023-09-14 00:05:02 -04:00
committed by GitHub
parent 503c808929
commit 088bea026e
2 changed files with 24 additions and 1 deletions

View File

@@ -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();

View File

@@ -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);
});