summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-read-stream-throw-type-error.js
diff options
context:
space:
mode:
authorUjjwal Sharma <usharma1998@gmail.com>2018-04-03 23:04:20 +0530
committerLuigi Pinca <luigipinca@gmail.com>2018-04-06 10:51:35 +0200
commit38a692963f000e3bd0f8413617d3b5774039dff8 (patch)
tree58cd6a782ae60504beaafc0b614fa06767d8c44b /test/parallel/test-fs-read-stream-throw-type-error.js
parent496d6023e0c372c76746c35fdba800fa943cbffc (diff)
downloadandroid-node-v8-38a692963f000e3bd0f8413617d3b5774039dff8.tar.gz
android-node-v8-38a692963f000e3bd0f8413617d3b5774039dff8.tar.bz2
android-node-v8-38a692963f000e3bd0f8413617d3b5774039dff8.zip
fs: make ReadStream throw TypeError on NaN
Make ReadStream (and thus createReadStream) throw a TypeError signalling towards an invalid argument type when either options.start or options.end (or obviously, both) are set to NaN. Also add regression tests for the same. PR-URL: https://github.com/nodejs/node/pull/19775 Fixes: https://github.com/nodejs/node/issues/19715 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-read-stream-throw-type-error.js')
-rw-r--r--test/parallel/test-fs-read-stream-throw-type-error.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/parallel/test-fs-read-stream-throw-type-error.js b/test/parallel/test-fs-read-stream-throw-type-error.js
index c2b0d5452c..5cba76fa39 100644
--- a/test/parallel/test-fs-read-stream-throw-type-error.js
+++ b/test/parallel/test-fs-read-stream-throw-type-error.js
@@ -3,6 +3,9 @@ const common = require('../common');
const fixtures = require('../common/fixtures');
const fs = require('fs');
+// This test ensures that appropriate TypeError is thrown by createReadStream
+// when an argument with invalid type is passed
+
const example = fixtures.path('x.txt');
// Should not throw.
fs.createReadStream(example, undefined);
@@ -25,3 +28,8 @@ createReadStreamErr(example, 123);
createReadStreamErr(example, 0);
createReadStreamErr(example, true);
createReadStreamErr(example, false);
+
+// createReadSteam _should_ throw on NaN
+createReadStreamErr(example, { start: NaN });
+createReadStreamErr(example, { end: NaN });
+createReadStreamErr(example, { start: NaN, end: NaN });