buffer: allow invalid encoding in from

Looks like a bug to me but the change should probably
done in a semver majpr.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Robert Nagy 2024-08-27 06:01:30 +02:00 committed by GitHub
parent b39fad6052
commit c00ea01f2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -476,7 +476,7 @@ function createFromString(string, ops, length = ops.byteLength(string)) {
function fromString(string, encoding) {
let ops;
if (!encoding || encoding === 'utf8') {
if (!encoding || encoding === 'utf8' || typeof encoding !== 'string') {
ops = encodingOps.utf8;
} else {
ops = getEncodingOps(encoding);

View File

@ -139,3 +139,6 @@ throws(() => {
code: 'ERR_OUT_OF_RANGE',
})
);
// Invalid encoding is allowed
Buffer.from('asd', 1);