-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
options.defaultEncoding not validated in stream.Writable constructor #46301
Comments
I'll open a PR to validate encodings |
There is this comment in writable streams (but its also in readable). node/lib/internal/streams/writable.js Lines 121 to 126 in 762a3a8
@mcollina @ronag can give more context on why node/lib/internal/streams/readable.js Lines 177 to 184 in 762a3a8
|
I don't think there is any specific reason why it's not validated. PR welcome. |
PR-URL: #46322 Fixes: #46301 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Version
v19.4.0
Platform
Microsoft Windows NT 10.0.22000.0 x64
Subsystem
node:stream
What steps will reproduce the bug?
Create a new
stream.Writeable
and supply an invalid encoding fordefaultEncoding
. It will accept the encoding just fine, which can lead to some strange side effects.For a very quick test, just to show that it does not validate it:
For a more complete test that shows more of its effects:
How often does it reproduce? Is there a required condition?
As far as I can tell, it always reproduces.
What is the expected behavior?
I would expect the
stream.Writeable
constructor to validate thedefaultEncoding
option and throw an error if it is invalid.It still can throw an error with a call to
writeable.write
ifobjectMode
is false,decodeStrings
is true, thechunk
is a string, and no encoding is specified in the write call. Weirdly enough, it doesn't throw an error if thedefaultEncoding
is something other than a string, like a number or object, and converts the string provided in the write call to a buffer anyway.What do you see instead?
It does not validate invalid default encodings in the constructor, and only throws an error if the invalid default encoding is used (such as if a string is provided in a write call with no other encoding specified).
Additional information
Trying a similar thing with
stream.Readable
throws an error instead.The text was updated successfully, but these errors were encountered: