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 authored and GitHub committed 2024-08-27 04:01:30 +00:00
1 parent b39fad6052
commit c00ea01f2b
2 files changed
+4 -1

No files matched your search

+1 -1
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);
+3
View File
@@ -139,3 +139,6 @@ throws(() => {
code: 'ERR_OUT_OF_RANGE',
})
);
// Invalid encoding is allowed
Buffer.from('asd', 1);