Skip to content

Commit

Permalink
Fix merging of Buffer objects
Browse files Browse the repository at this point in the history
Previously, if you attempted to `build`/`create` an object whose properties contained `Buffer`s, they would be converted from the native `Buffer` type into an array (and thus creating an _incorrect_ value). This is caused by the use of lodash's `merge` implementation (see lodash/lodash#2964).

The recommended solution from the lodash project is to define a merge `customizer` to specifically handle this situation, which is what we do here.
  • Loading branch information
sds committed Apr 30, 2022
1 parent 2e56717 commit 444a261
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const mergeCustomizer = (
key: 'string',
object: any,
) => {
if (Array.isArray(srcVal)) {
if (Array.isArray(srcVal) || srcVal instanceof Buffer) {
return srcVal;
} else if (srcVal === undefined) {
object[key] = srcVal;
Expand Down

0 comments on commit 444a261

Please sign in to comment.