Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix issue #1834

  • Loading branch information...
commit d22abaf1a51197de95a2c4ba1391ee6b997590c7 1 parent cf5edb9
@chetverikov chetverikov authored Aaron Heckmann committed
Showing with 38 additions and 4 deletions.
  1. +2 −0  lib/document.js
  2. +36 −4 test/errors.validation.test.js
View
2  lib/document.js
@@ -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;
}
View
40 test/errors.validation.test.js
@@ -14,16 +14,48 @@ 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;
@@ -31,9 +63,9 @@ describe('ValidationError', function(){
m.validate(function (err) {
assert.doesNotThrow(function(){
String(err)
- })
+ });
done();
});
})
})
-})
+});
Please sign in to comment.
Something went wrong with that request. Please try again.