Permalink
Browse files

fix issue #1834

  • Loading branch information...
chetverikov authored and Aaron Heckmann committed Dec 18, 2013
1 parent cf5edb9 commit d22abaf1a51197de95a2c4ba1391ee6b997590c7
Showing with 38 additions and 4 deletions.
  1. +2 −0 lib/document.js
  2. +36 −4 test/errors.validation.test.js
View
@@ -1013,6 +1013,8 @@ Document.prototype.invalidate = function (path, err, val) {
err = new ValidatorError(path, err, 'user defined', val)
}
+ if (this.$__.validationError == err) return;
+
this.$__.validationError.errors[path] = err;
}
@@ -14,26 +14,58 @@ var assert = require('assert')
, ValidationError = mongoose.Document.ValidationError
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(){
it('does not cause RangeError (gh-1296)', function(done){
var ASchema = new Schema({
key: {type: String, required: true}
, value: {type:String, required: true}
- })
+ });
var BSchema = new Schema({
contents: [ASchema]
- })
+ });
var M = mongoose.model('A', BSchema);
var m = new M;
m.contents.push({ key: 'asdf' });
m.validate(function (err) {
assert.doesNotThrow(function(){
String(err)
- })
+ });
done();
});
})
})
-})
+});

0 comments on commit d22abaf

Please sign in to comment.