Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 493a6bb

Browse files
AJ ONealisaacs
AJ ONeal
authored andcommittedFeb 27, 2012
[ISSUE #2554 #2567] throw if fs args for 'start' or 'end' are strings
1 parent ba0892b commit 493a6bb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎lib/fs.js

+8
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,13 @@ var ReadStream = fs.ReadStream = function(path, options) {
11251125
if (this.encoding) this.setEncoding(this.encoding);
11261126

11271127
if (this.start !== undefined) {
1128+
if ('number' !== typeof this.start) {
1129+
throw TypeError('start must be a Number');
1130+
}
11281131
if (this.end === undefined) {
11291132
this.end = Infinity;
1133+
} else if ('number' !== typeof this.end) {
1134+
throw TypeError('end must be a Number');
11301135
}
11311136

11321137
if (this.start > this.end) {
@@ -1313,6 +1318,9 @@ var WriteStream = fs.WriteStream = function(path, options) {
13131318
}
13141319

13151320
if (this.start !== undefined) {
1321+
if ('number' !== typeof this.start) {
1322+
throw TypeError('start must be a Number');
1323+
}
13161324
if (this.start < 0) {
13171325
throw new Error('start must be >= zero');
13181326
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var assert = require('assert'),
2+
fs = require('fs'),
3+
saneEmitter,
4+
sanity = 'ire(\'assert\')';
5+
6+
saneEmitter = fs.createReadStream(__filename, { start: 17, end: 29 });
7+
8+
assert.throws(function () {
9+
fs.createReadStream(__filename, { start: "17", end: 29 });
10+
}, "start as string didn't throw an error for createReadStream");
11+
12+
assert.throws(function () {
13+
fs.createReadStream(__filename, { start: 17, end: "29" });
14+
}, "end as string didn't throw an error");
15+
16+
assert.throws(function () {
17+
fs.createWriteStream(__filename, { start: "17" });
18+
}, "start as string didn't throw an error for createWriteStream");
19+
20+
saneEmitter.on('data', function (data) {
21+
// a sanity check when using numbers instead of strings
22+
assert.strictEqual(sanity, data.toString('utf8'), 'read ' +
23+
data.toString('utf8') + ' instead of ' + sanity);
24+
});

0 commit comments

Comments
 (0)