Skip to content

Commit 84bf93b

Browse files
ronagtargos
authored andcommitted
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy