Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 8 additions & 9 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,16 @@ function byteLength(string, encoding) {
}

const len = string.length;
const mustMatch = (arguments.length > 2 && arguments[2] === true);
if (!mustMatch && len === 0)
if (len === 0)
return 0;

if (!encoding)
return (mustMatch ? -1 : byteLengthUtf8(string));

const ops = getEncodingOps(encoding);
if (ops === undefined)
return (mustMatch ? -1 : byteLengthUtf8(string));
return ops.byteLength(string);
if (encoding) {
const ops = getEncodingOps(encoding);
if (ops) {
return ops.byteLength(string);
}
}
return byteLengthUtf8(string);
}

Buffer.byteLength = byteLength;
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const vm = require('vm');
);
});

assert.strictEqual(Buffer.byteLength('', undefined, true), -1);

assert(ArrayBuffer.isView(new Buffer(10)));
assert(ArrayBuffer.isView(new SlowBuffer(10)));
assert(ArrayBuffer.isView(Buffer.alloc(10)));
Expand Down