mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
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>
17 lines
393 B
JavaScript
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);
|