-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
test: complete coverage of buffer #12831
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the comment to start with a capital letter, but maybe it's just me, idk :)
test/parallel/test-buffer-write.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
cjihrig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use Buffer.isEncoding() here?
8da6576 to
3202a99
Compare
|
Landed in a710e44 |
PR-URL: #12831 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: nodejs#12831 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
|
Should this be backported to |
Complete coverage of
lib/buffer.js. According to https://coverage.nodejs.org/coverage-ff001c12b032c33d/root/buffer.js.html , this PR adds the coverage for some missingbreakcases and oneutf-8case which are not get covered in #12714 .PS: When i was writing the test cases for those invalid encodings cases, i found that the way each
BufferAPI treats the invalid value of theencodingparameter seems quite inconsistent, for instance:Buffer.fromtreats all JavaScript falsy values and all other non-string values asutf8Buffer.from('foo', false)equalsBuffer.from('foo', 'utf8')Buffer.from('foo', 123)equalsBuffer.from('foo', 'utf8')buf.toStringonly treatsundefinedasutf8, and throws an error when comes to all other invalid valuesBuffer.from('foo').toString(undefined)equalsBuffer.from('foo').toString('utf8')Buffer.from('foo').toString('u')andBuffer.from('foo').toString(0)will throwbuf.writejust treats all JavaScript falsy value asutf8, and throws an error when comes to all other invalid valuesBuffer.alloc(9).write('foo', 0)equalsBuffer.alloc(9).write('foo', 'utf8')So shall we find a consistent way to deal with this invalid encoding parameter situation to avoid some potential confusions?
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test