Files
node/test/parallel/test-stream2-read-correct-num-bytes-in-utf8.js
T
Thomas Watson d10104bd94 stream: fix decoded fromList chunk boundary check
Correct `fromList()` in decoded string mode to compare `n` against the
current chunk length, not the buffer array length.

This prevents over-consuming chunks, which can corrupt readable state
and crash with `TypeError` when mixing `setEncoding()` and `read(n)`.

PR-URL: https://github.com/nodejs/node/pull/61884
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-02-22 00:19:40 +00:00

17 lines
393 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { Readable } = require('stream');
const readable = new Readable({ read() {} });
readable.setEncoding('utf8');
readable.push('abc');
readable.push('defgh');
readable.push(null);
assert.strictEqual(readable.read(5), 'abcde');
assert.strictEqual(readable.read(3), 'fgh');
assert.strictEqual(readable.read(1), null);