mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +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:
parent
b39fad6052
commit
c00ea01f2b
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user