From c1c0a7d494044f88e71404b356083aea38493a4f Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 2 Mar 2026 14:30:39 +0100 Subject: [PATCH] Skip enqueue of empty chunks in TextDecoderStream After BOM stripping or when receiving an empty Uint8Array, the decoded input can be zero-length. Per spec, empty chunks should produce no output rather than enqueuing an empty string. --- .../tests/streams/text_decoder_stream.html | 21 +++++++++++++++++++ .../webapi/encoding/TextDecoderStream.zig | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/browser/tests/streams/text_decoder_stream.html b/src/browser/tests/streams/text_decoder_stream.html index 37bae8b4..cf38a2fd 100644 --- a/src/browser/tests/streams/text_decoder_stream.html +++ b/src/browser/tests/streams/text_decoder_stream.html @@ -59,3 +59,24 @@ testing.expectEqual(true, result2.done); })(); + + diff --git a/src/browser/webapi/encoding/TextDecoderStream.zig b/src/browser/webapi/encoding/TextDecoderStream.zig index 2c4605ed..2ba1e501 100644 --- a/src/browser/webapi/encoding/TextDecoderStream.zig +++ b/src/browser/webapi/encoding/TextDecoderStream.zig @@ -65,6 +65,9 @@ fn decodeTransform(controller: *TransformStream.DefaultController, chunk: js.Val input = input[3..]; } + // Per spec, empty chunks produce no output + if (input.len == 0) return; + try controller.enqueue(.{ .string = input }); }