merge
merge copied to clipboard
version 2.x converts regular expressions to objects when cloning
Thanks for sharing merge. When upgrading from v1 to v2 I found the following bug. Bit confused as what could have caused it as the clone code doesn't seem to have changed greatly (other than being converted to TypeScript)
const merge = require('merge');
const result = merge.recursive(true, { regex: /.*/ } , {});
console.log(result);
v1.x
{ regex: /.*/ }
v2.x
{ regex: {} }
This is the problem. It incorrectly assumes that anything with with typeof object that is not an array is a plain object.
export function isPlainObject(input: any): input is Object {
return input && typeof input === 'object' && !Array.isArray(input)
}
The code previously had a custom function to determine the type.
function typeOf(input) {
return ({}).toString.call(input).slice(8, -1).toLowerCase();
}
@cressie176 I realize this is slightly off-topic, but are you aware of any other breaking changes in 2.x? I'm thinking of updating this dep in a few places. Nothing was documented that I can see, and it doesn't appear there were any intentional changes to the API with the Typescript migration, but I thought I'd ask around to be safe.
@yeikos care to weigh in?
This bug recently bit me and required more than a day of sleuthing before I figured it out. Hard to believe it is still an open issue more than 18 months after getting reported, especially since @cressie176 pointed out where the problem lies.
Closed via e9bea183aa374810ab2262639e303eb0500e6790.