From 16bf24f51bc0c9637b649085c5aed0f47ca7527b Mon Sep 17 00:00:00 2001 From: Fei Liu Date: Tue, 27 Aug 2019 17:46:39 +0200 Subject: [PATCH] Boolean as fill using Buffer.alloc --- index.js | 2 ++ test/node/test-buffer-alloc.js | 1 + 2 files changed, 3 insertions(+) diff --git a/index.js b/index.js index 92a3abb..3a4fc7a 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 03cc26d..030bad3 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); -- 2.34.1