Skip to content

Commit 5840138

Browse files
committed
stream: fix undefined in Readable object mode
Fixes `this.push(undefined)`. Fixes: #13753 PR-URL: #13760 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Calvin Metcalf <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 57b7285 commit 5840138

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lib/_stream_readable.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
215215
stream.emit('error', er);
216216
} else if (state.objectMode || chunk && chunk.length > 0) {
217217
if (typeof chunk !== 'string' &&
218-
Object.getPrototypeOf(chunk) !== Buffer.prototype &&
219-
!state.objectMode) {
218+
!state.objectMode &&
219+
Object.getPrototypeOf(chunk) !== Buffer.prototype) {
220220
chunk = Stream._uint8ArrayToBuffer(chunk);
221221
}
222222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Readable, Writable, Transform } = require('stream');
5+
6+
{
7+
const stream = new Readable({
8+
objectMode: true,
9+
read: common.mustCall(() => {
10+
stream.push(undefined);
11+
stream.push(null);
12+
})
13+
});
14+
15+
stream.on('data', common.mustCall((chunk) => {
16+
assert.strictEqual(chunk, undefined);
17+
}));
18+
}
19+
20+
{
21+
const stream = new Writable({
22+
objectMode: true,
23+
write: common.mustCall((chunk) => {
24+
assert.strictEqual(chunk, undefined);
25+
})
26+
});
27+
28+
stream.write(undefined);
29+
}
30+
31+
{
32+
const stream = new Transform({
33+
objectMode: true,
34+
transform: common.mustCall((chunk) => {
35+
stream.push(chunk);
36+
})
37+
});
38+
39+
stream.on('data', common.mustCall((chunk) => {
40+
assert.strictEqual(chunk, undefined);
41+
}));
42+
43+
stream.write(undefined);
44+
}

0 commit comments

Comments
 (0)