mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -139,3 +139,6 @@ throws(() => {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
})
|
||||
);
|
||||
|
||||
// Invalid encoding is allowed
|
||||
Buffer.from('asd', 1);
|
||||
|
||||
Reference in New Issue
Block a user