TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

Stack blown with deepmerge.all() using isMergeableObject #206

Closed nonara closed 3 years ago

nonara commented 3 years ago

Hello. Thanks for your work on deepmerge!

When using all with isMergeableObject and a nested object, it blows the stack in an infinite recursion scenario.

Reproduction:

deepmerge.all([ 
  { "headers": { "h1": "value", "h2": "value" } }, 
  { "b": 3 } 
], { isMergeableObject: () => true })
TehShrike commented 3 years ago

What would the fix be here, other than "fix your isMergeableObject implementation"?

nonara commented 3 years ago

Ok. I had a look at the code. isMergeableObject is typed isMergeableObject?(value: object): boolean, so I assumed that it was only passing elements which had the object js type. It's actually passing primitives as well.

Adding a typeof value === 'object' check to my isMergeableObject fixes the crash.

Might be worth it to change the call signature to (value:any): boolean

TehShrike commented 3 years ago

hmm, so that's an issue with the TS typings then