Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 2.x converts regular expressions to objects when cloning #41

Closed
cressie176 opened this issue Mar 27, 2021 · 4 comments
Closed

Comments

@cressie176
Copy link

cressie176 commented Mar 27, 2021

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: {} }
@cressie176
Copy link
Author

cressie176 commented Mar 27, 2021

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();
}

@dmellstrom
Copy link

@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?

@tferrin
Copy link

tferrin commented Sep 30, 2022

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.

juanrgm added a commit that referenced this issue May 5, 2023
@juanrgm
Copy link
Member

juanrgm commented May 5, 2023

Closed via e9bea18.

@juanrgm juanrgm closed this as completed May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants