Skip to content

Commit

Permalink
fix(shell/interpreter): don't always pass absolute path to spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed May 24, 2024
1 parent 6c9b3de commit d963370
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/shell/interpreter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4621,12 +4621,18 @@ 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;
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;
};
if (bun.Environment.isWindows and !bun.strings.eqlComptime(std.fs.path.extension(absolute_path), ".exe")) {
break :blk std.fs.path.basename(absolute_path);
}
this.writeFailingError("bun: command not found: {s}\n", .{first_arg});
return;
break :blk absolute_path;
};

const duped = arena_allocator.dupeZ(u8, bun.span(resolved)) catch bun.outOfMemory();
Expand Down
5 changes: 5 additions & 0 deletions test/js/bun/shell/bunshell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit d963370

Please sign in to comment.