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

Add cloneOf or clone method check in clone function to handle odd cloning situations #8299

Closed
stieg opened this issue Nov 4, 2019 · 1 comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@stieg
Copy link
Contributor

stieg commented Nov 4, 2019

Do you want to request a feature or report a bug?
Feature
What is the current behavior?
clone function falls back to valueOf, leading to a situation where valueOf may not give you the cloned value you seek.

If the current behavior is a bug, please provide the steps to reproduce.
See mongoosejs/mongoose-double#7 for background on the issue that lead to this ticket.

What is the expected behavior?
valueOf should return a clone but this is not always possible. Thus we need a method that we can seek and call to generate a proper clone

Suggest adding a cloneOf or clone method (similar to what is done for SchemaTypes) so we can support this would be great.

Per private email conversation with @vkarpov15

At first glance I think it is better to make Mongoose clone handle doubles without relying on valueOf as a clone. Please open up an issue in the mongoose GitHub repo.

@vkarpov15 vkarpov15 added this to the 5.7.9 milestone Nov 6, 2019
@vkarpov15 vkarpov15 added the enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature label Nov 6, 2019
@stieg
Copy link
Contributor Author

stieg commented Nov 6, 2019

I will have a PR for this shortly.

stieg added a commit to stieg/mongoose that referenced this issue Nov 6, 2019
Adds a check in the `clone` function to see if the given parameter has
a `cloneOf` method.  If the method exists then the `clone` method
assumes that this method will return a clone of the called object and
thus invokes it to complete its task.

Fixes Automattic#8299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants