diff --git a/lib/buffer.js b/lib/buffer.js index f125806622d49d..8f4e34d289fc27 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -276,6 +276,9 @@ function byteLength(string, encoding) { if (typeof(string) !== 'string') string = String(string); + if (string.length === 0) + return 0; + switch (encoding) { case 'ascii': case 'binary':