-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Buffer.isEncoding regards an empty string as a valid encoding #9654
Comments
I also vote for option 2 ( |
@nodejs/buffer |
I'm going to put a |
IMO, it would be consistent for Buffer.from('x', '') // ok, defaults to utf-8
Buffer.from('x', true) // ok, defaults to utf-8
Buffer.from('x', false) // ok, defaults to utf-8
// etc. The alternative is to make Another alternative is to simply state in the documentation that |
I'd definitely support this, |
I'm in favor of that approach. |
I'm going to abstain from taking a position on this because the implications could be quite broad, but I will point out that this logic isn't quite right:
Just because |
This got fixed in 452eed9 |
As stated in the issue title,
Buffer.isEncoding('')
returnstrue
.Actually, passing an empty string to
encoding
options offs.readFile
,Buffer.from
or other functions supportingencoding
doesn't result in an error, because they use the default encodingutf8
as a fallback in that case.From this point of view,
''
is also a valid encoding andBuffer.isEncoding('') === true
looks fine. However, if we approve this behavior ofBuffer.isEncoding
, I think it's inconsistent thatBuffer.isEncoding
returnsfalse
when it takes other falsy values −false
,null
,undefined
etc.So, which design of
Buffer.isEncoding
is most reasonable?Buffer.isEncoding
.Buffer.isEncoding
should returnfalse
when it takes''
.Buffer.isEncoding
should returntrue
when it takes any falsy values.I support the second one and can create a pull request.
I'd like to hear your opinion. Thanks.
The text was updated successfully, but these errors were encountered: