Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Halliday <mail@substack.net>2014-06-09 05:58:53 +0400
committerTrevor Norris <trev.norris@gmail.com>2014-08-02 00:01:23 +0400
commit8e2cc69e7883b0a8d97a2f62e301ece209f61352 (patch)
treeaa65969debf8820834ac55a4dc04a0aa42846bcf
parent92518892ec8d99a04cee9d51ab071087f06032d2 (diff)
stream: fix Readable.wrap objectMode falsy values
A streams1 stream will have its falsy values such as 0, false, or "" eaten by the upgrade to streams2, even when objectMode is enabled. Include test for said cases. Reviewed-by: isaacs <i@izs.me> Reviewed-by: Trevor Norris <trev.norris@gmail.com>
-rwxr-xr-xlib/_stream_readable.js7
-rw-r--r--test/simple/test-stream2-readable-wrap.js3
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index ae04f22fe94..1b29676e00d 100755
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -810,7 +810,12 @@ Readable.prototype.wrap = function(stream) {
stream.on('data', function(chunk) {
if (state.decoder)
chunk = state.decoder.write(chunk);
- if (!chunk || !state.objectMode && !chunk.length)
+
+ // don't skip over falsy values in objectMode
+ //if (state.objectMode && util.isNullOrUndefined(chunk))
+ if (state.objectMode && (chunk === null || chunk === undefined))
+ return;
+ else if (!state.objectMode && (!chunk || !chunk.length))
return;
var ret = self.push(chunk);
diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js
index 6b272be46bf..233e7fd26df 100644
--- a/test/simple/test-stream2-readable-wrap.js
+++ b/test/simple/test-stream2-readable-wrap.js
@@ -102,6 +102,9 @@ function runTest(highWaterMark, objectMode, produce) {
runTest(10, false, function(){ return new Buffer('xxxxxxxxxx'); });
runTest(1, true, function(){ return { foo: 'bar' }; });
+var objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ];
+runTest(1, true, function(){ return objectChunks.shift() });
+
process.on('exit', function() {
assert.equal(testRuns, completedRuns);
console.log('ok');