fs: check argument type on createStream method#1845
fs: check argument type on createStream method#1845yosuke-furukawa wants to merge 1 commit intonodejs:masterfrom yosuke-furukawa:fix/fs/stream
Conversation
|
Please re-review for document and test. |
There was a problem hiding this comment.
Perhaps use loose equality here to grab null also? It'll avoid an Object.create(null) call too.
There was a problem hiding this comment.
It might be better to change the check on line 1624 to else if (options === null || typeof options !== 'object')
There was a problem hiding this comment.
latest node and io.js accept null on fs.createReadStream.
current pull request does not change the behavior on fs.createReadStream, accepts string and throws proper exception.
if we don't accept null, this api may break the compatibility.
There was a problem hiding this comment.
Current versions accept null and any other falsey value so this is still a breaking change. If this were to land, it would make sense to throw on null, since this is already a breaking change and null is not a useful value to support here. This needs to be given a lot of consideration, especially after the events of this past weekend.
There was a problem hiding this comment.
Why is this already a breaking change (disregarding null)?
There was a problem hiding this comment.
Because fs.createReadStream() currently allows any falsey value (false, NaN, etc.). Under this PR, passing in false, for example, would throw.
There was a problem hiding this comment.
options = options || {} used to allow other falsy values as well.
There was a problem hiding this comment.
hm. OK. I will disallow null.
our current spec is to allow object only.
And under this PR, we can use string as an encoding.
So, this function allows object and string. the other types are not allowed.
If we found disallowed type, we should throw TypeError.
But null is unclear type.
I think null and undefined are not easy to use properly for beginner.
So my first impression, we should allow null just like undefined.
But I will follow @cjihrig suggestion. his spec is clear.
|
Fixed styles. |
|
I will land this. |
Add string encoding option for fs.createReadStream and fs.createWriteStream. and check argument type more strictly PR-URL: #1845 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
landed 353e26e |
|
@yosuke-furukawa looks like this wasn't properly signed-off on. It's best to wait for an explicit |
|
hm,,, I got some review and gets I just separate the pull request. But I should be careful more and more. |
separeted #1412
On Node.js v0.12
On io.js v1.6.4
I added document and fixed test to avoid linter errors.