diff --git a/index.js b/index.js index 92a3abbd..3a4fc7aa 100644 --- a/index.js +++ b/index.js @@ -1592,6 +1592,8 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } } else if (typeof val === 'number') { val = val & 255 + } else if (typeof val === 'boolean') { + val = Number(val) } // Invalid ranges are not set to a default, so can range check early. diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index 03cc26d0..030bad35 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -74,6 +74,7 @@ assert.doesNotThrow(() => new Buffer('', 'ascii')); assert.doesNotThrow(() => new Buffer('', 'latin1')); assert.doesNotThrow(() => new Buffer('', 'binary')); assert.doesNotThrow(() => Buffer(0)); +assert.doesNotThrow(() => Buffer.alloc(16, !!true)); // try to write a 0-length string beyond the end of b assert.throws(() => b.write('', 2048), RangeError);