You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
buffer.toString() no longer accepts null as encoding #13936
To be fair though, fixing this use case and the original use case (passing 0 as the first argument to toString()) detailed in the PR that made this change would be as simple as changing === undefined to == undefined.
Whether we'd want to support such a change is another question (e.g. would anyone complain about not accepting false for example?).
Another +1 from me for keeping the 8.x behavior. I did not review the original PR because I saw it already had lots of love - but I'm definitely in favor of the behavior change.
@vsemozhetbyt One small request … can you leave off the version-specific labels if the issue is the same on master? Otherwise it seems like the issue is only occuring on v8.x. :)
Why is this the expected behavior? The signature of the method is:
buffer.toString([encoding[,start[,end]]])
So encoding is an optional argument. However, where is it written that passing encoding = undefined means "use the default value"? Is there any rule out there stating that undefined is the only way to mean that while null is invalid?
However, it might be a good idea to document that explicitly.
So encoding is an optional argument.
Per the signature, it's only optional if start and end aren't specified, otherwise it would be buffer.toString([encoding][, start[, end]]) or something like that.
Per the signature, it's only optional if start and end aren't specified, otherwise it would be buffer.toString([encoding][, start[, end]]) or something like that.
Activity
vsemozhetbyt commentedon Jun 26, 2017
It is most likely caused by the #11120 and listed among the semver-major changes.
mscdex commentedon Jun 26, 2017
To be fair though, fixing this use case and the original use case (passing
0as the first argument totoString()) detailed in the PR that made this change would be as simple as changing=== undefinedto== undefined.Whether we'd want to support such a change is another question (e.g. would anyone complain about not accepting
falsefor example?).ibc commentedon Jun 26, 2017
I understand the rationale given in #11120. However, shouldn't
nullbe also valid (and not justundefined) forencoding?seishun commentedon Jun 27, 2017
nullwas never documented as a "valid" encoding, so I don't see any reason to support it. It's just more ground for confusion.benjamingr commentedon Jun 27, 2017
Another +1 from me for keeping the 8.x behavior. I did not review the original PR because I saw it already had lots of love - but I'm definitely in favor of the behavior change.
addaleax commentedon Jun 30, 2017
@vsemozhetbyt One small request … can you leave off the version-specific labels if the issue is the same on master? Otherwise it seems like the issue is only occuring on v8.x. :)
seishun commentedon Jun 30, 2017
Closing as expected behavior.
ibc commentedon Jun 30, 2017
Why is this the expected behavior? The signature of the method is:
So
encodingis an optional argument. However, where is it written that passingencoding = undefinedmeans "use the default value"? Is there any rule out there stating thatundefinedis the only way to mean that whilenullis invalid?seishun commentedon Jun 30, 2017
That's how default arguments work in JavaScript in general:
However, it might be a good idea to document that explicitly.
Per the signature, it's only optional if
startandendaren't specified, otherwise it would bebuffer.toString([encoding][, start[, end]])or something like that.ibc commentedon Jun 30, 2017
Good and clarifying code snip. Thanks.
Completely right. Thanks, I was wrong.