Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ function slowToString(encoding, start, end) {
if (end <= start)
return '';

if (!encoding) encoding = 'utf8';
if (encoding === undefined) encoding = 'utf8';

while (true) {
switch (encoding) {
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-buffer-tostring-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ assert.strictEqual(rangeBuffer.toString('ascii', 0, true), 'a');
assert.strictEqual(rangeBuffer.toString({toString: function() {
return 'ascii';
}}), 'abc');

// try toString() with 0 and null as the encoding
assert.throws(() => rangeBuffer.toString(0, 1, 2), /^TypeError: Unknown encoding: 0$/);
assert.throws(() => rangeBuffer.toString(null, 1, 2), /^TypeError: Unknown encoding: null$/);