deepmerge icon indicating copy to clipboard operation
deepmerge copied to clipboard

When source is undefined, mergedeep returns source

Open shivakanthreddy opened this issue 8 months ago • 1 comments

_deepmerge(target, source) returns source when source is undefined, rather it should be target.

example: ` const deepmergeFastify = require('@fastify/deepmerge')({clone: false}) let target: {key: value} const source: undefined

target = deepmergeFastify(target, source) // target will be undefined here

But target should be returned as is. I suspect the issue might be at this line https://github.com/fastify/deepmerge/blob/main/index.js#L136

shivakanthreddy avatar Mar 24 '25 11:03 shivakanthreddy

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Mar 27 '25 10:03 mcollina

Is the intended/expected behavior to return target? For instance, Object.assing() throws an error when target is undefined or null and with the proposed fix it will return the target value.

> Object.assign(undefined, {})
Uncaught TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)

lucas-sodtrack avatar Jun 06 '25 05:06 lucas-sodtrack