8000 buffer: throw if Buffer.from() receives a function by cjihrig · Pull Request #26743 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Buffer.from = function from(value, encodingOrOffset, length) {
if (isAnyArrayBuffer(value))
return fromArrayBuffer(value, encodingOrOffset, length);

if (value === null || value === undefined) {
if (value === null || value === undefined || typeof value === 'function') {
throw new ERR_INVALID_ARG_TYPE(
'first argument',
['string', 'Buffer', 'ArrayBuffer', 'Array', 'Array-like Object'],
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-buffer-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ deepStrictEqual(
[{ valueOf() { return null; } }, 'object'],
[{ valueOf() { return undefined; } }, 'object'],
[{ valueOf: null }, 'object'],
[Object.create(null), 'object']
[Object.create(null), 'object'],
[() => {}, 'function']
].forEach(([input, actualType]) => {
const err = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
Expand Down
0