mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
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.
This commit is contained in:
@@ -59,3 +59,24 @@
|
|||||||
testing.expectEqual(true, result2.done);
|
testing.expectEqual(true, result2.done);
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=text_decoder_stream_empty_chunk>
|
||||||
|
(async function() {
|
||||||
|
const tds = new TextDecoderStream();
|
||||||
|
const writer = tds.writable.getWriter();
|
||||||
|
const reader = tds.readable.getReader();
|
||||||
|
|
||||||
|
// Write an empty chunk followed by real data
|
||||||
|
await writer.write(new Uint8Array([]));
|
||||||
|
await writer.write(new Uint8Array([104, 105]));
|
||||||
|
await writer.close();
|
||||||
|
|
||||||
|
// Empty chunk should be filtered out; first read gets "hi"
|
||||||
|
const result = await reader.read();
|
||||||
|
testing.expectEqual(false, result.done);
|
||||||
|
testing.expectEqual('hi', result.value);
|
||||||
|
|
||||||
|
const result2 = await reader.read();
|
||||||
|
testing.expectEqual(true, result2.done);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ fn decodeTransform(controller: *TransformStream.DefaultController, chunk: js.Val
|
|||||||
input = input[3..];
|
input = input[3..];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Per spec, empty chunks produce no output
|
||||||
|
if (input.len == 0) return;
|
||||||
|
|
||||||
try controller.enqueue(.{ .string = input });
|
try controller.enqueue(.{ .string = input });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user