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