Skip to content

Commit 84bf93b

Browse files
ronagtargos
authored andcommittedOct 2, 2024
buffer: allow invalid encoding in from
Looks like a bug to me but the change should probably done in a semver majpr. PR-URL: #54533 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 7f8edce commit 84bf93b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
 

‎lib/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ function createFromString(string, ops, length = ops.byteLength(string)) {
474474

475475
function fromString(string, encoding) {
476476
let ops;
477-
if (!encoding || encoding === 'utf8') {
477+
if (!encoding || encoding === 'utf8' || typeof encoding !== 'string') {
478478
ops = encodingOps.utf8;
479479
} else {
480480
ops = getEncodingOps(encoding);

‎test/parallel/test-buffer-from.js

+3
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@ throws(() => {
139139
code: 'ERR_OUT_OF_RANGE',
140140
})
141141
);
142+
143+
// Invalid encoding is allowed
144+
Buffer.from('asd', 1);

0 commit comments

Comments
 (0)
Please sign in to comment.