Skip to content

Commit

Permalink
Merge pull request #243 from geastwood/fill-boolean
Browse files Browse the repository at this point in the history
Boolean as fill using Buffer.alloc
  • Loading branch information
feross authored Aug 27, 2019
2 parents d31e0ee + 16bf24f commit 509d39d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/node/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 509d39d

Please sign in to comment.