Skip to content

Commit

Permalink
fix issue #1834
Browse files Browse the repository at this point in the history
  • Loading branch information
chetverikov authored and Aaron Heckmann committed Jan 7, 2014
1 parent cf5edb9 commit d22abaf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/document.js
Expand Up @@ -1013,6 +1013,8 @@ Document.prototype.invalidate = function (path, err, val) {
err = new ValidatorError(path, err, 'user defined', val) err = new ValidatorError(path, err, 'user defined', val)
} }


if (this.$__.validationError == err) return;

this.$__.validationError.errors[path] = err; this.$__.validationError.errors[path] = err;
} }


Expand Down
40 changes: 36 additions & 4 deletions test/errors.validation.test.js
Expand Up @@ -14,26 +14,58 @@ var assert = require('assert')
, ValidationError = mongoose.Document.ValidationError , ValidationError = mongoose.Document.ValidationError


describe('ValidationError', function(){ describe('ValidationError', function(){
describe('#infiniteRecursion', function(){
it('does not cause RangeError (gh-1834)', function(done){
var SubSchema
, M
, model;

SubSchema = new Schema({
name: {type: String, required: true},
contents: [new Schema({
key: {type: String, required: true},
value: {type: String, required: true}
}, {_id: false})]
});

M = mongoose.model('SubSchema', SubSchema);

model = new M({
name: 'Model',
contents: [
{ key: 'foo' }
]
});

model.validate(function(err){
assert.doesNotThrow(function(){
JSON.stringify(err);
});
done();
});
})
});

describe('#toString', function(){ describe('#toString', function(){
it('does not cause RangeError (gh-1296)', function(done){ it('does not cause RangeError (gh-1296)', function(done){
var ASchema = new Schema({ var ASchema = new Schema({
key: {type: String, required: true} key: {type: String, required: true}
, value: {type:String, required: true} , value: {type:String, required: true}
}) });


var BSchema = new Schema({ var BSchema = new Schema({
contents: [ASchema] contents: [ASchema]
}) });


var M = mongoose.model('A', BSchema); var M = mongoose.model('A', BSchema);
var m = new M; var m = new M;
m.contents.push({ key: 'asdf' }); m.contents.push({ key: 'asdf' });
m.validate(function (err) { m.validate(function (err) {
assert.doesNotThrow(function(){ assert.doesNotThrow(function(){
String(err) String(err)
}) });
done(); done();
}); });
}) })
}) })
}) });

0 comments on commit d22abaf

Please sign in to comment.