mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 22:01:47 +00:00
@@ -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;
|
||||
},
|
||||
|
||||
15
test/cli/run/run-quote.test.ts
Normal file
15
test/cli/run/run-quote.test.ts
Normal 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}`);
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user