diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index f51669b5948db..0bc301d04360a 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1801,10 +1801,6 @@ pub const Subprocess = struct { while (cmds_array.next()) |value| { const arg = value.getZigString(globalThis); - // if the string is empty, ignore it, don't add it to the argv - if (arg.len == 0) { - continue; - } argv.appendAssumeCapacity(arg.toOwnedSliceZ(allocator) catch { globalThis.throwOutOfMemory(); return .zero; diff --git a/test/js/bun/spawn/empty-final-arg.js b/test/js/bun/spawn/empty-final-arg.js new file mode 100644 index 0000000000000..c462a6248e08f --- /dev/null +++ b/test/js/bun/spawn/empty-final-arg.js @@ -0,0 +1,5 @@ +if (process.argv[process.argv.length - 1] == "") { + process.exit(0); +} else { + process.exit(1); +} diff --git a/test/js/bun/spawn/spawn-empty-args.test.ts b/test/js/bun/spawn/spawn-empty-args.test.ts new file mode 100644 index 0000000000000..bd14bca120c0e --- /dev/null +++ b/test/js/bun/spawn/spawn-empty-args.test.ts @@ -0,0 +1,15 @@ +import { expect, test } from "bun:test"; +import { bunExe } from "harness"; +import { join } from "node:path"; + +test("handle empty argument", async () => { + const proc = Bun.spawn({ + cmd: [bunExe(), join(import.meta.dirname, "empty-final-arg.js"), ""], + stdin: "ignore", + stdout: "ignore", + stderr: "ignore", + }); + + const exited = await proc.exited; + expect(exited).toBe(0); +});