diff --git a/lib/helpers.js b/lib/helpers.js index cc6cd80..8034c71 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -67,7 +67,7 @@ ValidatorResult.prototype.importErrors = function importErrors(res) { if (typeof res == 'string' || (res && res.validatorType)) { this.addError(res); } else if (res && res.errors) { - Array.prototype.push.apply(this.errors, res.errors); + this.errors = this.errors.concat(res.errors) } }; diff --git a/test/Validator.test.js b/test/Validator.test.js index 6ed5f2f..9cdd0c3 100644 --- a/test/Validator.test.js +++ b/test/Validator.test.js @@ -6,6 +6,7 @@ var Validator = require('../lib/index.js').Validator; var SchemaError = require('../lib/index.js').SchemaError; var ValidationError = require('../lib/index.js').ValidationError; +var ValidatorResult = require('../lib/index.js').ValidatorResult; var ValidatorResultError = require('../lib/index.js').ValidatorResultError; var assert = require('assert'); @@ -282,6 +283,22 @@ describe('Validator', function () { return true; }); }); + it('million errors', function () { + var schema = { + type: 'number', + oneMillionErrors: true, + }; + validator.attributes.oneMillionErrors = function(instance, schema, options, ctx) { + const result = new ValidatorResult(instance, schema, options, ctx); + for(var i = 0; i < 1000000; i++) { + result.addError('oneMillionErrors error'); + } + return result; + } + var res = validator.validate(1, schema, {}); + assert(!res.valid); + assert.strictEqual(res.errors.length, 1000000); + }); it('subschema references (named reference)', function () { var schema = { items: {$ref: '#items'},