Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Possibly clone object before cleaning #182

Open aldeed opened 9 years ago

aldeed commented 9 years ago

Cleaning in the deny functions needs to mutate the object because that's the only way to alter the doc before it is inserted, but in the other two cases, we can clone to ensure no surprises for the user. Most likely a deep clone is necessary.

Add tests for this, and then fix such that they pass.

aldeed commented 9 years ago

See also https://github.com/aldeed/meteor-simple-schema/issues/250

It still seems best and easiest to continue mutating in the simple-schema clean method, but do a deep clone (EJSON.clone() maybe) before that in the collection2 code.