diff options
author | 2023-05-31 23:15:21 -0700 | |
---|---|---|
committer | 2023-05-31 23:15:21 -0700 | |
commit | fdcfcce9e762644477205cd8a5b7f66d4a6a9965 (patch) | |
tree | c19e473369313f1ddf6ad3e68e15f8d2c0687598 | |
parent | 1ca70b855cc067ea86df366171fe21621a96d138 (diff) | |
download | bun-fdcfcce9e762644477205cd8a5b7f66d4a6a9965.tar.gz bun-fdcfcce9e762644477205cd8a5b7f66d4a6a9965.tar.zst bun-fdcfcce9e762644477205cd8a5b7f66d4a6a9965.zip |
Clean-up some option parsing in Bun.spawn
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 0fb5a98be..a996f863b 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1114,7 +1114,14 @@ pub const Subprocess = struct { } while (cmds_array.next()) |value| { - argv.appendAssumeCapacity(value.getZigString(globalThis).toOwnedSliceZ(allocator) catch { + 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.throw("out of memory", .{}); return .zero; }); @@ -1128,11 +1135,15 @@ pub const Subprocess = struct { if (args != .zero and args.isObject()) { if (args.get(globalThis, "cwd")) |cwd_| { + // ignore definitely invalid cwd if (!cwd_.isEmptyOrUndefinedOrNull()) { - cwd = cwd_.getZigString(globalThis).toOwnedSliceZ(allocator) catch { - globalThis.throw("out of memory", .{}); - return .zero; - }; + const cwd_str = cwd_.getZigString(globalThis); + if (cwd_str.len > 0) { + cwd = cwd_str.toOwnedSliceZ(allocator) catch { + globalThis.throw("out of memory", .{}); + return .zero; + }; + } } } |