From 1c05351037334a33336c6fa96a62508ef7b72a15 Mon Sep 17 00:00:00 2001 From: Grigory Date: Fri, 24 May 2024 22:46:58 +0500 Subject: [PATCH] fix(shell/interpreter): don't always pass absolute path to spawn --- src/shell/interpreter.zig | 15 +++++++++------ test/js/bun/shell/bunshell.test.ts | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index e05dfb2029bb7..e59667c80bd95 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -4621,12 +4621,15 @@ pub const Interpreter = struct { } var path_buf: bun.PathBuffer = undefined; - const resolved = which(&path_buf, spawn_args.PATH, spawn_args.cwd, first_arg_real) orelse blk: { - if (bun.strings.eqlComptime(first_arg_real, "bun") or bun.strings.eqlComptime(first_arg_real, "bun-debug")) blk2: { - break :blk bun.selfExePath() catch break :blk2; - } - this.writeFailingError("bun: command not found: {s}\n", .{first_arg}); - return; + const resolved = blk: { + const absolute_path = which(&path_buf, spawn_args.PATH, spawn_args.cwd, first_arg_real) orelse blk2: { + if (bun.strings.eqlComptime(first_arg_real, "bun") or bun.strings.eqlComptime(first_arg_real, "bun-debug")) blk3: { + break :blk2 bun.selfExePath() catch break :blk3; + } + this.writeFailingError("bun: command not found: {s}\n", .{first_arg}); + return; + }; + break :blk std.fs.path.basename(absolute_path); }; const duped = arena_allocator.dupeZ(u8, bun.span(resolved)) catch bun.outOfMemory(); diff --git a/test/js/bun/shell/bunshell.test.ts b/test/js/bun/shell/bunshell.test.ts index 6e4588fcedb40..9d44be36bfd81 100644 --- a/test/js/bun/shell/bunshell.test.ts +++ b/test/js/bun/shell/bunshell.test.ts @@ -833,6 +833,11 @@ ${temp_dir}` .stdout("complex > command; $(execute)\n") .runAsTest("complex_mixed_special_chars"); }); + + test("spaces in path and args", async () => { + const fields = "name scripts"; + expect(async () => { await $`npm pkg get ${fields}` }).not.toThrow(); + }); }); describe("deno_task", () => {