Skip to content

Commit

Permalink
fixes invalid properties getting saved Automattic#644
Browse files Browse the repository at this point in the history
  • Loading branch information
nw committed Dec 16, 2011
1 parent 7765ab7 commit f87b50a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/document.js
Expand Up @@ -28,6 +28,9 @@ function Document (obj, fields) {
if (!this._events) this._events = {};
this.setMaxListeners(0);

this._strictMode = !this.options.lax;
if(!fields && 'boolean' === typeof fields) this._strictMode = true;

this._doc = this.buildDoc(fields);
this._activePaths = new ActiveRoster();
var self = this;
Expand Down Expand Up @@ -280,6 +283,8 @@ Document.prototype.set = function (path, val, type) {
if (null != path[key] && 'Object' === path[key].constructor.name
&& !(this._path(prefix + key) instanceof MixedSchema)) {
this.set(path[key], prefix + key);
} else if(this._strictMode == true){
if(this._path(prefix + key) !== undefined) this.set(prefix + key, path[key]);
} else if (undefined !== path[key]) {
this.set(prefix + key, path[key]);
}
Expand Down
1 change: 1 addition & 0 deletions lib/schema.js
Expand Up @@ -31,6 +31,7 @@ function Schema (obj, options) {
this.options = utils.options({
safe: true
, 'use$SetOnSave': true
, lax: true
}, options);

// build paths
Expand Down

0 comments on commit f87b50a

Please sign in to comment.