workaround quote escape issues for bun run (#3290)

fixes #53
This commit is contained in:
Alex Lam S.L
2023-06-13 15:38:10 +03:00
committed by GitHub
parent 067a0235e4
commit c8d06f04d3
3 changed files with 34 additions and 1 deletions

View File

@@ -192,6 +192,24 @@ pub const RunCommand = struct {
delimiter = 0;
},
// TODO: handle escape sequences properly
// https://github.com/oven-sh/bun/issues/53
'\\' => {
delimiter = 0;
if (entry_i + 1 < script.len) {
switch (script[entry_i + 1]) {
'"', '\'' => {
entry_i += 1;
continue;
},
'\\' => {
entry_i += 1;
},
else => {},
}
}
},
else => {
delimiter = 0;
},

View File

@@ -0,0 +1,15 @@
import { expect, it } from "bun:test";
import { bunRunAsScript, tempDirWithFiles } from "harness";
it("should handle quote escapes", () => {
const package_json = JSON.stringify({
scripts: {
test: `echo "test\\\\$(pwd)"`,
},
});
expect(package_json).toContain('\\"');
expect(package_json).toContain("\\\\");
const dir = tempDirWithFiles("run-quote", { "package.json": package_json });
const { stdout } = bunRunAsScript(dir, "test");
expect(stdout).toBe(`test\\${dir}`);
});

View File

@@ -81,7 +81,7 @@ export function hideFromStackTrace(block: CallableFunction) {
}
export function tempDirWithFiles(basename: string, files: Record<string, string>) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), basename + "_"));
const dir = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), basename + "_"));
for (const [name, contents] of Object.entries(files)) {
fs.writeFileSync(path.join(dir, name), contents);
}