Skip to content

Commit

Permalink
buffer: allow invalid encoding in from
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ronag authored and RafaelGSS committed Aug 30, 2024
1 parent fe56949 commit afd8c1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-buffer-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ throws(() => {
code: 'ERR_OUT_OF_RANGE',
})
);

// Invalid encoding is allowed
Buffer.from('asd', 1);

0 comments on commit afd8c1e

Please sign in to comment.