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

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎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
functionfromString(string,encoding){
476476
letops;
477-
if(!encoding||encoding==='utf8'){
477+
if(!encoding||encoding==='utf8'||typeofencoding!=='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)