mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Allow 0-length ArrayBuffer & Blob in Bun.spawn stdio (#9557)
Co-authored-by: Zack Radisic <zack@theradisic.com>
This commit is contained in:
@@ -409,9 +409,10 @@ pub const Stdio = union(enum) {
|
||||
}
|
||||
}
|
||||
} else if (value.asArrayBuffer(globalThis)) |array_buffer| {
|
||||
if (array_buffer.slice().len == 0) {
|
||||
globalThis.throwInvalidArguments("ArrayBuffer cannot be empty", .{});
|
||||
return false;
|
||||
// Change in Bun v1.0.34: don't throw for empty ArrayBuffer
|
||||
if (array_buffer.byteSlice().len == 0) {
|
||||
out_stdio.* = .{ .ignore = {} };
|
||||
return true;
|
||||
}
|
||||
|
||||
out_stdio.* = .{
|
||||
@@ -475,6 +476,12 @@ pub const Stdio = union(enum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Instead of writing an empty blob, lets just make it /dev/null
|
||||
if (blob.fastSize() == 0) {
|
||||
stdio.* = .{ .ignore = {} };
|
||||
return true;
|
||||
}
|
||||
|
||||
stdio.* = .{ .blob = blob };
|
||||
return true;
|
||||
}
|
||||
|
||||
29
test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts
Normal file
29
test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, test, expect } from "bun:test";
|
||||
import { bunEnv, bunExe } from "harness";
|
||||
|
||||
describe("spawn with empty", () => {
|
||||
for (const [stdin, label] of [
|
||||
[new ArrayBuffer(0), "ArrayBuffer"],
|
||||
[new Uint8Array(0), "Uint8Array"],
|
||||
[new Blob([]), "Blob"],
|
||||
] as const) {
|
||||
test(label + " for stdin", async () => {
|
||||
const proc = Bun.spawn({
|
||||
cmd: [bunExe(), "-e", "process.stdin.pipe(process.stdout)"],
|
||||
stdin,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
env: bunEnv,
|
||||
});
|
||||
|
||||
const [exited, stdout, stderr] = await Promise.all([
|
||||
proc.exited,
|
||||
new Response(proc.stdout).text(),
|
||||
new Response(proc.stderr).text(),
|
||||
]);
|
||||
expect(exited).toBe(0);
|
||||
expect(stdout).toBeEmpty();
|
||||
expect(stderr).toBeEmpty();
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user