Open jgabrielygalan opened 8 years ago
Oh, by the way, please note that due to the toEqual problem I mentioned, I needed to use something like checking the Regexp#source for equality. Also, I don't understand why in the second test I need to remove the check for circular references.
I am away from home right now and won't be back until Monday. I'll have to look into it then. What I'll try to do is follow the same convention as in everything else, I'd attempt to get information from the regex and create a new one with the same pattern and options. The properties created on the regex object would clone the original too. In the case of merging regex objects, the pattern would simply be replaced. I don't recall the specs for a regex object off hand, so handling modifiers depends on whether they're accessible properties or not. If the only thing I can do to reflect on the regex is call toSource and get some string representation of the pattern and modifiers all together, then I'd just replace it all and merge any other properties per the process that's already in place.
You're more than welcome to submit a pull request with the work you've done, I'd appreciate it. Also, if you have some ideas about how you'd like the patterns and modifiers to behave during a merge I'm open to hearing them. I do want to maintain some consistency with the way other objects get merged, but I also want this to be useful to you when we're done.
Thank you for pointing out this issue. On May 6, 2016 6:08 AM, "jgabrielygalan" notifications@github.com wrote:
Oh, by the way, please note that due to the toEqual problem I mentioned, I needed to use something like checking the Regexp#source for equality. Also, I don't understand why in the second test I need to remove the check for circular references.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/matthewkastor/object-merge/issues/7#issuecomment-217403178
Hi,
I was trying to merge objects that contain RegExp objects inside, and it doesn't work correctly. The culprit seems to be the objectForEach method from object-foreach, which is checking Object.keys(obj), which is empty for RegExp:
An additional problem seems to be that expect({}).toEqual(/.*/) passes, probably due to the same reasons (although jasmine-node seems to make a special case for RegExp, it doesn't work here).
These tests currently fail:
Failures:
1) object-merge clones regexp Message: Expected undefined to equal 'a.*'.
2) object-merge keeps regexp from last object Message: Expected undefined to equal 'd.*'.
We have managed to make it work with a simple patch (I can provide a pull request if you want), but we are not sure this would be the correct solution:
Add these lines to getOutputObject, before the check of Object (line 149):
With this patch, the tests pass. This will keep the last RegExp with the same key. I don't know if we should somehow merge two RegExps, maybe with a union, for example.