From c081061a1e6a998b65bd11aba7a0dc25b42d207d Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Fri, 1 Mar 2019 02:19:12 -0500 Subject: [PATCH 001/127] feat: invalidDefaults option to warn when defaults are ignored, fixes #957 --- README.md | 8 ++- lib/ajv.d.ts | 1 + lib/ajv.js | 2 +- lib/dot/defaults.def | 30 +++++++---- lib/dot/validate.jst | 9 +++- spec/options/useDefaults.spec.js | 88 +++++++++++++++++++++++++++++++- 6 files changed, 124 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5ddefa134..c26aa078d 100644 --- a/README.md +++ b/README.md @@ -798,13 +798,14 @@ console.log(validate(data)); // true console.log(data); // [ 1, "foo" ] ``` -`default` keywords in other cases are ignored: +`default` keywords in other cases are invalid: - not in `properties` or `items` subschemas - in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/epoberezkin/ajv/issues/42)) - in `if` subschema of `switch` keyword - in schemas generated by custom macro keywords +The [`invalidDefaults` option](#options) customizes Ajv's behavior for invalid defaults (`false` ignores invalid defaults, `true` raises an error, and `"log"` outputs a warning). ## Coercing data types @@ -1070,6 +1071,7 @@ Defaults: removeAdditional: false, useDefaults: false, coerceTypes: false, + invalidDefaults: false, // asynchronous validation options: transpile: undefined, // requires ajv-async package // advanced options: @@ -1151,6 +1153,10 @@ Defaults: - `false` (default) - no type coercion. - `true` - coerce scalar data types. - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema). +- _invalidDefaults_: specify behavior for invalid `default` keywords in schemas. Option values: + - `false` (default) - ignore invalid defaults + - `true` - if an invalid default is present, throw an error + - `"log"` - if an invalid default is present, log warning ##### Asynchronous validation options diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 8b0d9ab6d..bbba7a593 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -180,6 +180,7 @@ declare namespace ajv { removeAdditional?: boolean | 'all' | 'failing'; useDefaults?: boolean | 'shared'; coerceTypes?: boolean | 'array'; + invalidDefaults?: boolean | 'log'; async?: boolean | string; transpile?: string | ((code: string) => string); meta?: boolean | object; diff --git a/lib/ajv.js b/lib/ajv.js index 105315adb..0b975a28f 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -39,7 +39,7 @@ Ajv.$dataMetaSchema = $dataMetaSchema; var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema'; -var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ]; +var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'invalidDefaults' ]; var META_SUPPORT_DATA = ['/properties']; /** diff --git a/lib/dot/defaults.def b/lib/dot/defaults.def index f100cc4bf..3e4a8de00 100644 --- a/lib/dot/defaults.def +++ b/lib/dot/defaults.def @@ -1,15 +1,25 @@ {{## def.assignDefault: - if ({{=$passData}} === undefined - {{? it.opts.useDefaults == 'empty' }} - || {{=$passData}} === null - || {{=$passData}} === '' + {{? it.compositeRule }} + {{? it.opts.invalidDefaults }} + {{? it.opts.invalidDefaults === 'log' }} + {{ it.logger.warn('default is ignored for: ' + $passData); }} + {{??}} + {{ throw new Error('default is ignored for: ' + $passData); }} + {{?}} {{?}} - ) - {{=$passData}} = {{? it.opts.useDefaults == 'shared' }} - {{= it.useDefault($sch.default) }} - {{??}} - {{= JSON.stringify($sch.default) }} - {{?}}; + {{??}} + if ({{=$passData}} === undefined + {{? it.opts.useDefaults == 'empty' }} + || {{=$passData}} === null + || {{=$passData}} === '' + {{?}} + ) + {{=$passData}} = {{? it.opts.useDefaults == 'shared' }} + {{= it.useDefault($sch.default) }} + {{??}} + {{= JSON.stringify($sch.default) }} + {{?}}; + {{?}} #}} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index 89a5b3b49..4e05ce890 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -72,6 +72,13 @@ it.dataPathArr = [undefined]; }} + {{? it.opts.invalidDefaults && it.schema.default !== undefined }} + {{? it.opts.invalidDefaults === 'log' }} + {{ it.logger.warn('default is ignored in the schema root'); }} + {{??}} + {{ throw new Error('default is ignored in the schema root'); }} + {{?}} + {{?}} var vErrors = null; {{ /* don't edit, used in replace */ }} var errors = 0; {{ /* don't edit, used in replace */ }} @@ -177,7 +184,7 @@ {{? $rulesGroup.type }} if ({{= it.util.checkDataType($rulesGroup.type, $data) }}) { {{?}} - {{? it.opts.useDefaults && !it.compositeRule }} + {{? it.opts.useDefaults }} {{? $rulesGroup.type == 'object' && it.schema.properties }} {{# def.defaultProperties }} {{?? $rulesGroup.type == 'array' && Array.isArray(it.schema.items) }} diff --git a/spec/options/useDefaults.spec.js b/spec/options/useDefaults.spec.js index 7a12e8423..4570a326c 100644 --- a/spec/options/useDefaults.spec.js +++ b/spec/options/useDefaults.spec.js @@ -2,7 +2,7 @@ var Ajv = require('../ajv'); var getAjvInstances = require('../ajv_instances'); -require('../chai').should(); +var should = require('../chai').should(); describe('useDefaults options', function() { @@ -220,4 +220,90 @@ describe('useDefaults options', function() { }); }); }); + + describe('invalidDefaults option', function() { + it('should throw an error given an invalid default in the schema root when invalidDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, invalidDefaults: true}); + var schema = { + default: 5, + properties: {} + }; + should.throw(function() { ajv.compile(schema); }); + }); + + it('should throw an error given an invalid default in oneOf when invalidDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, invalidDefaults: true}); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + should.throw(function() { ajv.compile(schema); }); + }); + + it('should log a warning given an invalid default in the schema root when invalidDefaults is "log"', function() { + var warnArg = null; + var ajv = new Ajv({ + useDefaults: true, + invalidDefaults: 'log', + logger: { + log: function() { + throw new Error('should not be called'); + }, + warn: function(warning) { + warnArg = warning; + }, + error: function() { + throw new Error('should not be called'); + } + } + }); + var schema = { + default: 5, + properties: {} + }; + ajv.compile(schema); + should.equal(warnArg, 'default is ignored in the schema root'); + }); + + it('should log a warning given an invalid default in oneOf when invalidDefaults is "log"', function() { + var warnArg = null; + var ajv = new Ajv({ + useDefaults: true, + invalidDefaults: 'log', + logger: { + log: function() { + throw new Error('should not be called'); + }, + warn: function(warning) { + warnArg = warning; + }, + error: function() { + throw new Error('should not be called'); + } + } + }); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + ajv.compile(schema); + should.equal(warnArg, 'default is ignored for: data.foo'); + }); + }); }); From 88199d569c2d6d2123678bec08ba9a8ffcf841f1 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 09:16:00 +0000 Subject: [PATCH 002/127] rename option to strictDefaults --- README.md | 15 ++++++++------- lib/ajv.d.ts | 2 +- lib/ajv.js | 2 +- lib/dot/defaults.def | 9 +++++---- lib/dot/validate.jst | 9 +++++---- spec/options/useDefaults.spec.js | 18 +++++++++--------- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index c26aa078d..b61da8b13 100644 --- a/README.md +++ b/README.md @@ -798,14 +798,15 @@ console.log(validate(data)); // true console.log(data); // [ 1, "foo" ] ``` -`default` keywords in other cases are invalid: +`default` keywords in other cases are ignored: - not in `properties` or `items` subschemas - in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/epoberezkin/ajv/issues/42)) - in `if` subschema of `switch` keyword - in schemas generated by custom macro keywords -The [`invalidDefaults` option](#options) customizes Ajv's behavior for invalid defaults (`false` ignores invalid defaults, `true` raises an error, and `"log"` outputs a warning). +The [`strictDefaults` option](#options) customizes Ajv's behavior for the defaults that Ajv ignores (`true` raises an error, and `"log"` outputs a warning). + ## Coercing data types @@ -1071,7 +1072,7 @@ Defaults: removeAdditional: false, useDefaults: false, coerceTypes: false, - invalidDefaults: false, + strictDefaults: false, // asynchronous validation options: transpile: undefined, // requires ajv-async package // advanced options: @@ -1153,10 +1154,10 @@ Defaults: - `false` (default) - no type coercion. - `true` - coerce scalar data types. - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema). -- _invalidDefaults_: specify behavior for invalid `default` keywords in schemas. Option values: - - `false` (default) - ignore invalid defaults - - `true` - if an invalid default is present, throw an error - - `"log"` - if an invalid default is present, log warning +- _strictDefaults_: specify behavior for ignored `default` keywords in schemas. Option values: + - `false` (default) - ignored defaults are not reported + - `true` - if an ignored default is present, throw an error + - `"log"` - if an ignored default is present, log warning ##### Asynchronous validation options diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index bbba7a593..63f110a0d 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -180,7 +180,7 @@ declare namespace ajv { removeAdditional?: boolean | 'all' | 'failing'; useDefaults?: boolean | 'shared'; coerceTypes?: boolean | 'array'; - invalidDefaults?: boolean | 'log'; + strictDefaults?: boolean | 'log'; async?: boolean | string; transpile?: string | ((code: string) => string); meta?: boolean | object; diff --git a/lib/ajv.js b/lib/ajv.js index 0b975a28f..611b93835 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -39,7 +39,7 @@ Ajv.$dataMetaSchema = $dataMetaSchema; var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema'; -var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'invalidDefaults' ]; +var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ]; var META_SUPPORT_DATA = ['/properties']; /** diff --git a/lib/dot/defaults.def b/lib/dot/defaults.def index 3e4a8de00..ec6c70fe9 100644 --- a/lib/dot/defaults.def +++ b/lib/dot/defaults.def @@ -1,10 +1,11 @@ {{## def.assignDefault: {{? it.compositeRule }} - {{? it.opts.invalidDefaults }} - {{? it.opts.invalidDefaults === 'log' }} - {{ it.logger.warn('default is ignored for: ' + $passData); }} + {{? it.opts.strictDefaults }} + {{ var $defaultMsg = 'default is ignored for: ' + $passData; }} + {{? it.opts.strictDefaults === 'log' }} + {{ it.logger.warn($defaultMsg); }} {{??}} - {{ throw new Error('default is ignored for: ' + $passData); }} + {{ throw new Error($defaultMsg); }} {{?}} {{?}} {{??}} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index 4e05ce890..12a2fe494 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -72,11 +72,12 @@ it.dataPathArr = [undefined]; }} - {{? it.opts.invalidDefaults && it.schema.default !== undefined }} - {{? it.opts.invalidDefaults === 'log' }} - {{ it.logger.warn('default is ignored in the schema root'); }} + {{? it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults }} + {{ var $defaultMsg = 'default is ignored in the schema root'; }} + {{? it.opts.strictDefaults === 'log' }} + {{ it.logger.warn($defaultMsg); }} {{??}} - {{ throw new Error('default is ignored in the schema root'); }} + {{ throw new Error($defaultMsg); }} {{?}} {{?}} diff --git a/spec/options/useDefaults.spec.js b/spec/options/useDefaults.spec.js index 4570a326c..122d778d4 100644 --- a/spec/options/useDefaults.spec.js +++ b/spec/options/useDefaults.spec.js @@ -221,9 +221,9 @@ describe('useDefaults options', function() { }); }); - describe('invalidDefaults option', function() { - it('should throw an error given an invalid default in the schema root when invalidDefaults is true', function() { - var ajv = new Ajv({useDefaults: true, invalidDefaults: true}); + describe('strictDefaults option', function() { + it('should throw an error given an ignored default in the schema root when strictDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, strictDefaults: true}); var schema = { default: 5, properties: {} @@ -231,8 +231,8 @@ describe('useDefaults options', function() { should.throw(function() { ajv.compile(schema); }); }); - it('should throw an error given an invalid default in oneOf when invalidDefaults is true', function() { - var ajv = new Ajv({useDefaults: true, invalidDefaults: true}); + it('should throw an error given an ignored default in oneOf when strictDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, strictDefaults: true}); var schema = { oneOf: [ { enum: ['foo', 'bar'] }, @@ -248,11 +248,11 @@ describe('useDefaults options', function() { should.throw(function() { ajv.compile(schema); }); }); - it('should log a warning given an invalid default in the schema root when invalidDefaults is "log"', function() { + it('should log a warning given an ignored default in the schema root when strictDefaults is "log"', function() { var warnArg = null; var ajv = new Ajv({ useDefaults: true, - invalidDefaults: 'log', + strictDefaults: 'log', logger: { log: function() { throw new Error('should not be called'); @@ -273,11 +273,11 @@ describe('useDefaults options', function() { should.equal(warnArg, 'default is ignored in the schema root'); }); - it('should log a warning given an invalid default in oneOf when invalidDefaults is "log"', function() { + it('should log a warning given an ignored default in oneOf when strictDefaults is "log"', function() { var warnArg = null; var ajv = new Ajv({ useDefaults: true, - invalidDefaults: 'log', + strictDefaults: 'log', logger: { log: function() { throw new Error('should not be called'); From 18268c5f38be48f1d95781e264365b193100954b Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 09:36:26 +0000 Subject: [PATCH 003/127] additional tests for strictDefault options --- spec/options/strictDefaults.spec.js | 166 ++++++++++++++++++++++++++++ spec/options/useDefaults.spec.js | 86 -------------- 2 files changed, 166 insertions(+), 86 deletions(-) create mode 100644 spec/options/strictDefaults.spec.js diff --git a/spec/options/strictDefaults.spec.js b/spec/options/strictDefaults.spec.js new file mode 100644 index 000000000..ef48dd0d7 --- /dev/null +++ b/spec/options/strictDefaults.spec.js @@ -0,0 +1,166 @@ +'use strict'; + +var Ajv = require('../ajv'); +var getAjvInstances = require('../ajv_instances'); +var should = require('../chai').should(); + + +describe('strictDefaults option', function() { + describe('useDefaults = true', function() { + describe('strictDefaults = false', function() { + it('should NOT throw an error or log a warning given an ignored default', function() { + var output = {}; + var ajv = new Ajv({ + useDefaults: true, + strictDefaults: false, + logger: getLogger(output) + }); + var schema = { + default: 5, + properties: {} + }; + + ajv.compile(schema); + should.not.exist(output.warning); + }); + + it('should NOT throw an error or log a warning given an ignored default', function() { + var output = {}; + var ajv = new Ajv({ + useDefaults: true, + strictDefaults: false, + logger: getLogger(output) + }); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + + ajv.compile(schema); + should.not.exist(output.warning); + }); + }); + + describe('strictDefaults = true', function() { + it('should throw an error given an ignored default in the schema root when strictDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, strictDefaults: true}); + var schema = { + default: 5, + properties: {} + }; + should.throw(function() { ajv.compile(schema); }); + }); + + it('should throw an error given an ignored default in oneOf when strictDefaults is true', function() { + var ajv = new Ajv({useDefaults: true, strictDefaults: true}); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + should.throw(function() { ajv.compile(schema); }); + }); + }); + + describe('strictDefaults = "log"', function() { + it('should log a warning given an ignored default in the schema root when strictDefaults is "log"', function() { + var output = {}; + var ajv = new Ajv({ + useDefaults: true, + strictDefaults: 'log', + logger: getLogger(output) + }); + var schema = { + default: 5, + properties: {} + }; + ajv.compile(schema); + should.equal(output.warning, 'default is ignored in the schema root'); + }); + + it('should log a warning given an ignored default in oneOf when strictDefaults is "log"', function() { + var output = {}; + var ajv = new Ajv({ + useDefaults: true, + strictDefaults: 'log', + logger: getLogger(output) + }); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + ajv.compile(schema); + should.equal(output.warning, 'default is ignored for: data.foo'); + }); + }); + }); + + + describe('useDefaults = false', function() { + describe('strictDefaults = true', function() { + it('should NOT throw an error given an ignored default in the schema root when useDefaults is false', function() { + var ajv = new Ajv({useDefaults: false, strictDefaults: true}); + var schema = { + default: 5, + properties: {} + }; + should.not.throw(function() { ajv.compile(schema); }); + }); + + it('should NOT throw an error given an ignored default in oneOf when useDefaults is false', function() { + var ajv = new Ajv({useDefaults: false, strictDefaults: true}); + var schema = { + oneOf: [ + { enum: ['foo', 'bar'] }, + { + properties: { + foo: { + default: true + } + } + } + ] + }; + should.not.throw(function() { ajv.compile(schema); }); + }); + }); + }); + + + function getLogger(output) { + return { + log: function() { + throw new Error('log should not be called'); + }, + warn: function(warning) { + output.warning = warning; + }, + error: function() { + throw new Error('error should not be called'); + } + } + } +}); diff --git a/spec/options/useDefaults.spec.js b/spec/options/useDefaults.spec.js index 122d778d4..7d8329e5e 100644 --- a/spec/options/useDefaults.spec.js +++ b/spec/options/useDefaults.spec.js @@ -220,90 +220,4 @@ describe('useDefaults options', function() { }); }); }); - - describe('strictDefaults option', function() { - it('should throw an error given an ignored default in the schema root when strictDefaults is true', function() { - var ajv = new Ajv({useDefaults: true, strictDefaults: true}); - var schema = { - default: 5, - properties: {} - }; - should.throw(function() { ajv.compile(schema); }); - }); - - it('should throw an error given an ignored default in oneOf when strictDefaults is true', function() { - var ajv = new Ajv({useDefaults: true, strictDefaults: true}); - var schema = { - oneOf: [ - { enum: ['foo', 'bar'] }, - { - properties: { - foo: { - default: true - } - } - } - ] - }; - should.throw(function() { ajv.compile(schema); }); - }); - - it('should log a warning given an ignored default in the schema root when strictDefaults is "log"', function() { - var warnArg = null; - var ajv = new Ajv({ - useDefaults: true, - strictDefaults: 'log', - logger: { - log: function() { - throw new Error('should not be called'); - }, - warn: function(warning) { - warnArg = warning; - }, - error: function() { - throw new Error('should not be called'); - } - } - }); - var schema = { - default: 5, - properties: {} - }; - ajv.compile(schema); - should.equal(warnArg, 'default is ignored in the schema root'); - }); - - it('should log a warning given an ignored default in oneOf when strictDefaults is "log"', function() { - var warnArg = null; - var ajv = new Ajv({ - useDefaults: true, - strictDefaults: 'log', - logger: { - log: function() { - throw new Error('should not be called'); - }, - warn: function(warning) { - warnArg = warning; - }, - error: function() { - throw new Error('should not be called'); - } - } - }); - var schema = { - oneOf: [ - { enum: ['foo', 'bar'] }, - { - properties: { - foo: { - default: true - } - } - } - ] - }; - ajv.compile(schema); - should.equal(warnArg, 'default is ignored for: data.foo'); - }); - }); }); From 9a286893407918367a08bba6375869adac5f4ef8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 09:41:23 +0000 Subject: [PATCH 004/127] style: fix --- spec/options/strictDefaults.spec.js | 5 ++--- spec/options/useDefaults.spec.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/options/strictDefaults.spec.js b/spec/options/strictDefaults.spec.js index ef48dd0d7..1f1093a69 100644 --- a/spec/options/strictDefaults.spec.js +++ b/spec/options/strictDefaults.spec.js @@ -1,7 +1,6 @@ 'use strict'; var Ajv = require('../ajv'); -var getAjvInstances = require('../ajv_instances'); var should = require('../chai').should(); @@ -43,7 +42,7 @@ describe('strictDefaults option', function() { } ] }; - + ajv.compile(schema); should.not.exist(output.warning); }); @@ -161,6 +160,6 @@ describe('strictDefaults option', function() { error: function() { throw new Error('error should not be called'); } - } + }; } }); diff --git a/spec/options/useDefaults.spec.js b/spec/options/useDefaults.spec.js index 7d8329e5e..7a12e8423 100644 --- a/spec/options/useDefaults.spec.js +++ b/spec/options/useDefaults.spec.js @@ -2,7 +2,7 @@ var Ajv = require('../ajv'); var getAjvInstances = require('../ajv_instances'); -var should = require('../chai').should(); +require('../chai').should(); describe('useDefaults options', function() { From e993bd6b4e6ca28487cdfea7aede37d141dd13d5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 10:49:16 +0000 Subject: [PATCH 005/127] feat: strictKeywords option to report unknown keywords, closes #781 --- README.md | 12 +++++- lib/compile/rules.js | 2 +- lib/compile/util.js | 7 +++ lib/dot/validate.jst | 11 +++++ spec/custom.spec.js | 3 ++ spec/options/strictKeywords.spec.js | 66 +++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 spec/options/strictKeywords.spec.js diff --git a/README.md b/README.md index b61da8b13..c858efd09 100644 --- a/README.md +++ b/README.md @@ -1072,7 +1072,9 @@ Defaults: removeAdditional: false, useDefaults: false, coerceTypes: false, + // strict mode options strictDefaults: false, + strictKeywords: false, // asynchronous validation options: transpile: undefined, // requires ajv-async package // advanced options: @@ -1154,10 +1156,18 @@ Defaults: - `false` (default) - no type coercion. - `true` - coerce scalar data types. - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema). -- _strictDefaults_: specify behavior for ignored `default` keywords in schemas. Option values: + + +##### Strict mode options + +- _strictDefaults_: report ignored `default` keywords in schemas. Option values: - `false` (default) - ignored defaults are not reported - `true` - if an ignored default is present, throw an error - `"log"` - if an ignored default is present, log warning +- _strictKeywords_: report unknown keywords in schemas. Option values: + - `false` (default) - unknown keywords are not reported + - `true` - if an unknown keyword is present, throw an error + - `"log"` - if an unknown keyword is present, log warning ##### Asynchronous validation options diff --git a/lib/compile/rules.js b/lib/compile/rules.js index 66f196a93..08b25aeb9 100644 --- a/lib/compile/rules.js +++ b/lib/compile/rules.js @@ -20,7 +20,7 @@ module.exports = function rules() { var ALL = [ 'type', '$comment' ]; var KEYWORDS = [ - '$schema', '$id', 'id', '$data', 'title', + '$schema', '$id', 'id', '$data', '$async', 'title', 'description', 'default', 'definitions', 'examples', 'readOnly', 'writeOnly', 'contentMediaType', 'contentEncoding', diff --git a/lib/compile/util.js b/lib/compile/util.js index 263891c33..0efa00111 100644 --- a/lib/compile/util.js +++ b/lib/compile/util.js @@ -17,6 +17,7 @@ module.exports = { finalCleanUpCode: finalCleanUpCode, schemaHasRules: schemaHasRules, schemaHasRulesExcept: schemaHasRulesExcept, + schemaUnknownRules: schemaUnknownRules, toQuotedString: toQuotedString, getPathExpr: getPathExpr, getPath: getPath, @@ -183,6 +184,12 @@ function schemaHasRulesExcept(schema, rules, exceptKeyword) { } +function schemaUnknownRules(schema, rules) { + if (typeof schema == 'boolean') return; + for (var key in schema) if (!rules[key]) return key; +} + + function toQuotedString(str) { return '\'' + escapeQuotes(str) + '\''; } diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index 12a2fe494..3c92ef441 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -20,6 +20,17 @@ , $id = it.self._getId(it.schema); }} +{{ + if (it.opts.strictKeywords) { + var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords); + if ($unknownKwd) { + var $keywordsMsg = 'unknown keyword: ' + $unknownKwd; + if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg); + else throw new Error($keywordsMsg); + } + } +}} + {{? it.isTop }} var validate = {{?$async}}{{it.async = true;}}async {{?}}function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; diff --git a/spec/custom.spec.js b/spec/custom.spec.js index 5b1b6f03a..2924fceea 100644 --- a/spec/custom.spec.js +++ b/spec/custom.spec.js @@ -415,6 +415,7 @@ describe('Custom keywords', function () { it('should correctly expand macros in macro expansions', function() { instances.forEach(function (_ajv) { _ajv.addKeyword('range', { type: 'number', macro: macroRange }); + _ajv.addKeyword('exclusiveRange', { metaSchema: {type: 'boolean'} }); _ajv.addKeyword('myContains', { type: 'array', macro: macroContains }); var schema = { @@ -811,6 +812,7 @@ describe('Custom keywords', function () { function testRangeKeyword(definition, customErrors, numErrors) { instances.forEach(function (_ajv) { _ajv.addKeyword('x-range', definition); + _ajv.addKeyword('exclusiveRange', {metaSchema: {type: 'boolean'}}); var schema = { "x-range": [2, 4] }; var validate = _ajv.compile(schema); @@ -849,6 +851,7 @@ describe('Custom keywords', function () { function testMultipleRangeKeyword(definition, numErrors) { instances.forEach(function (_ajv) { _ajv.addKeyword('x-range', definition); + _ajv.addKeyword('exclusiveRange', {metaSchema: {type: 'boolean'}}); var schema = { "properties": { diff --git a/spec/options/strictKeywords.spec.js b/spec/options/strictKeywords.spec.js new file mode 100644 index 000000000..b212d15c7 --- /dev/null +++ b/spec/options/strictKeywords.spec.js @@ -0,0 +1,66 @@ +'use strict'; + +var Ajv = require('../ajv'); +var should = require('../chai').should(); + + +describe('strictKeywords option', function() { + describe('strictKeywords = false', function() { + it('should NOT throw an error or log a warning given an unknown keyword', function() { + var output = {}; + var ajv = new Ajv({ + strictKeywords: false, + logger: getLogger(output) + }); + var schema = { + properties: {}, + unknownKeyword: 1 + }; + + ajv.compile(schema); + should.not.exist(output.warning); + }); + }); + + describe('strictKeywords = true', function() { + it('should throw an error given an unknown keyword in the schema root when strictKeywords is true', function() { + var ajv = new Ajv({strictKeywords: true}); + var schema = { + properties: {}, + unknownKeyword: 1 + }; + should.throw(function() { ajv.compile(schema); }); + }); + }); + + describe('strictKeywords = "log"', function() { + it('should log a warning given an unknown keyword in the schema root when strictKeywords is "log"', function() { + var output = {}; + var ajv = new Ajv({ + strictKeywords: 'log', + logger: getLogger(output) + }); + var schema = { + properties: {}, + unknownKeyword: 1 + }; + ajv.compile(schema); + should.equal(output.warning, 'unknown keyword: unknownKeyword'); + }); + }); + + + function getLogger(output) { + return { + log: function() { + throw new Error('log should not be called'); + }, + warn: function(warning) { + output.warning = warning; + }, + error: function() { + throw new Error('error should not be called'); + } + }; + } +}); From 38d1acddade54dc6193c47d431880bd102336621 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 10:54:16 +0000 Subject: [PATCH 006/127] refactor: strictDefaults option --- lib/dot/defaults.def | 15 +++++++-------- lib/dot/validate.jst | 14 ++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/dot/defaults.def b/lib/dot/defaults.def index ec6c70fe9..a844cf285 100644 --- a/lib/dot/defaults.def +++ b/lib/dot/defaults.def @@ -1,13 +1,12 @@ {{## def.assignDefault: {{? it.compositeRule }} - {{? it.opts.strictDefaults }} - {{ var $defaultMsg = 'default is ignored for: ' + $passData; }} - {{? it.opts.strictDefaults === 'log' }} - {{ it.logger.warn($defaultMsg); }} - {{??}} - {{ throw new Error($defaultMsg); }} - {{?}} - {{?}} + {{ + if (it.opts.strictDefaults) { + var $defaultMsg = 'default is ignored for: ' + $passData; + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg); + else throw new Error($defaultMsg); + } + }} {{??}} if ({{=$passData}} === undefined {{? it.opts.useDefaults == 'empty' }} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index 3c92ef441..f8a1edfc0 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -82,15 +82,13 @@ delete it.isTop; it.dataPathArr = [undefined]; + + if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) { + var $defaultMsg = 'default is ignored in the schema root'; + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg); + else throw new Error($defaultMsg); + } }} - {{? it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults }} - {{ var $defaultMsg = 'default is ignored in the schema root'; }} - {{? it.opts.strictDefaults === 'log' }} - {{ it.logger.warn($defaultMsg); }} - {{??}} - {{ throw new Error($defaultMsg); }} - {{?}} - {{?}} var vErrors = null; {{ /* don't edit, used in replace */ }} var errors = 0; {{ /* don't edit, used in replace */ }} From 6c20483b6690af2c7eb760826f00ed6b37488cbb Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 3 Mar 2019 11:09:23 +0000 Subject: [PATCH 007/127] 6.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 32026c5b6..fda68f3b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.9.2", + "version": "6.10.0", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From d10720734d806fd25606dafd47b64e97ee7d1e7d Mon Sep 17 00:00:00 2001 From: Romain DARY Date: Sun, 3 Mar 2019 16:46:16 +0100 Subject: [PATCH 008/127] Fix wrong json schema reference (#961) `examples` is a new keyword introduce in `draft-06`. Source : [JSON Schema Draft 6 MetaSchema](http://json-schema.org/draft-06/schema) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c858efd09..575861e55 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ JSON Schema specification defines several annotation keywords that describe sche - `title` and `description`: information about the data represented by that schema - `$comment` (NEW in draft-07): information for developers. With option `$comment` Ajv logs or passes the comment string to the user-supplied function. See [Options](#options). - `default`: a default value of the data instance, see [Assigning defaults](#assigning-defaults). -- `examples` (NEW in draft-07): an array of data instances. Ajv does not check the validity of these instances against the schema. +- `examples` (NEW in draft-06): an array of data instances. Ajv does not check the validity of these instances against the schema. - `readOnly` and `writeOnly` (NEW in draft-07): marks data-instance as read-only or write-only in relation to the source of the data (database, api, etc.). - `contentEncoding`: [RFC 2045](https://tools.ietf.org/html/rfc2045#section-6.1 ), e.g., "base64". - `contentMediaType`: [RFC 2046](https://tools.ietf.org/html/rfc2046), e.g., "image/png". From 78a940367cd7fd392d8b8d89d646dfdc2350652d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Apr 2019 20:34:35 +0100 Subject: [PATCH 009/127] update JSON-Schema-Test-Suite --- spec/JSON-Schema-Test-Suite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/JSON-Schema-Test-Suite b/spec/JSON-Schema-Test-Suite index 86f965e53..15ba997f9 160000 --- a/spec/JSON-Schema-Test-Suite +++ b/spec/JSON-Schema-Test-Suite @@ -1 +1 @@ -Subproject commit 86f965e53dda0b6c57e70ddd726243e1e061cf84 +Subproject commit 15ba997f9b937150a0ab88244d1d0fbf58526c48 From 6be5ff65f94a6a5127a404ea03f7607c7f29ebaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C6=87=CA=98=C6=81=CC=86=C4=85=C6=87=CC=81?= Date: Mon, 8 Apr 2019 18:53:01 +0200 Subject: [PATCH 010/127] fix(types): add strictKeywords to Options interface (#975) --- lib/ajv.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 63f110a0d..8b29c5bde 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -181,6 +181,7 @@ declare namespace ajv { useDefaults?: boolean | 'shared'; coerceTypes?: boolean | 'array'; strictDefaults?: boolean | 'log'; + strictKeywords?: boolean | 'log'; async?: boolean | string; transpile?: string | ((code: string) => string); meta?: boolean | object; From bc993deceada5cc152ba0fd3b2e300012b2330a0 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 8 Apr 2019 17:53:27 +0100 Subject: [PATCH 011/127] chore(package): update karma to version 4.0.1 (#959) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fda68f3b9..24257407a 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "js-beautify": "^1.7.3", "jshint": "2.9.7", "json-schema-test": "^2.0.0", - "karma": "^3.0.0", + "karma": "^4.0.1", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", From ab841b462ec4baff37d2a7319cef13820b53d963 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 27 Apr 2019 10:32:39 +0100 Subject: [PATCH 012/127] fix: addKeyword and schema without ID, closes #1001 --- lib/definition_schema.js | 37 +++++++++++++++++++ lib/keyword.js | 34 +---------------- spec/JSON-Schema-Test-Suite | 2 +- ...1_addKeyword_and_schema_without_id.spec.js | 20 ++++++++++ 4 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 lib/definition_schema.js create mode 100644 spec/issues/1001_addKeyword_and_schema_without_id.spec.js diff --git a/lib/definition_schema.js b/lib/definition_schema.js new file mode 100644 index 000000000..e5f6b911c --- /dev/null +++ b/lib/definition_schema.js @@ -0,0 +1,37 @@ +'use strict'; + +var metaSchema = require('./refs/json-schema-draft-07.json'); + +module.exports = { + $id: 'https://github.com/epoberezkin/ajv/blob/master/lib/definition_schema.js', + definitions: { + simpleTypes: metaSchema.definitions.simpleTypes + }, + type: 'object', + dependencies: { + schema: ['validate'], + $data: ['validate'], + statements: ['inline'], + valid: {not: {required: ['macro']}} + }, + properties: { + type: metaSchema.properties.type, + schema: {type: 'boolean'}, + statements: {type: 'boolean'}, + dependencies: { + type: 'array', + items: {type: 'string'} + }, + metaSchema: {type: 'object'}, + modifying: {type: 'boolean'}, + valid: {type: 'boolean'}, + $data: {type: 'boolean'}, + async: {type: 'boolean'}, + errors: { + anyOf: [ + {type: 'boolean'}, + {const: 'full'} + ] + } + } +}; diff --git a/lib/keyword.js b/lib/keyword.js index cf4d699b3..5fec19a67 100644 --- a/lib/keyword.js +++ b/lib/keyword.js @@ -2,7 +2,7 @@ var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i; var customRuleCode = require('./dotjs/custom'); -var metaSchema = require('./refs/json-schema-draft-07.json'); +var definitionSchema = require('./definition_schema'); module.exports = { add: addKeyword, @@ -11,38 +11,6 @@ module.exports = { validate: validateKeyword }; -var definitionSchema = { - definitions: { - simpleTypes: metaSchema.definitions.simpleTypes - }, - type: 'object', - dependencies: { - schema: ['validate'], - $data: ['validate'], - statements: ['inline'], - valid: {not: {required: ['macro']}} - }, - properties: { - type: metaSchema.properties.type, - schema: {type: 'boolean'}, - statements: {type: 'boolean'}, - dependencies: { - type: 'array', - items: {type: 'string'} - }, - metaSchema: {type: 'object'}, - modifying: {type: 'boolean'}, - valid: {type: 'boolean'}, - $data: {type: 'boolean'}, - async: {type: 'boolean'}, - errors: { - anyOf: [ - {type: 'boolean'}, - {const: 'full'} - ] - } - } -}; /** * Define custom keyword diff --git a/spec/JSON-Schema-Test-Suite b/spec/JSON-Schema-Test-Suite index 15ba997f9..eadeacb04 160000 --- a/spec/JSON-Schema-Test-Suite +++ b/spec/JSON-Schema-Test-Suite @@ -1 +1 @@ -Subproject commit 15ba997f9b937150a0ab88244d1d0fbf58526c48 +Subproject commit eadeacb04209a18fc81f1a1959e83eef72dcc97a diff --git a/spec/issues/1001_addKeyword_and_schema_without_id.spec.js b/spec/issues/1001_addKeyword_and_schema_without_id.spec.js new file mode 100644 index 000000000..bc3d0d7d0 --- /dev/null +++ b/spec/issues/1001_addKeyword_and_schema_without_id.spec.js @@ -0,0 +1,20 @@ +'use strict'; + +var Ajv = require('../ajv'); +require('../chai').should(); + + +describe('issue #1001: addKeyword breaks schema without ID', function() { + it('should allow using schemas without ID with addKeyword', function() { + var schema = { + definitions: { + foo: {} + } + }; + + var ajv = new Ajv(); + ajv.addSchema(schema); + ajv.addKeyword('myKeyword', {}); + ajv.getSchema('#/definitions/foo') .should.be.a('function'); + }); +}); From c3093bbd6a587024d551dc43e996d22e0ecde04e Mon Sep 17 00:00:00 2001 From: vanessa <32312712+vlbee@users.noreply.github.com> Date: Fri, 5 Jul 2019 22:22:00 +0100 Subject: [PATCH 013/127] Add "empty" to useDefaults Option type definition (#1020) --- lib/ajv.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 8b29c5bde..5e7cfa7da 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -178,7 +178,7 @@ declare namespace ajv { extendRefs?: true | 'ignore' | 'fail'; loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike; removeAdditional?: boolean | 'all' | 'failing'; - useDefaults?: boolean | 'shared'; + useDefaults?: boolean | 'empty' | 'shared'; coerceTypes?: boolean | 'array'; strictDefaults?: boolean | 'log'; strictKeywords?: boolean | 'log'; From 120d746154f1200d2c2a8c6c643b35691d01ea64 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2019 22:23:00 +0100 Subject: [PATCH 014/127] chore(package): update nyc to version 14.0.0 (#994) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 24257407a..190993f2f 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", "mocha": "^6.0.0", - "nyc": "^13.2.0", + "nyc": "^14.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", "typescript": "^2.8.3", From 3ca7571330ae1d772074e07d00500deef2173061 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Jul 2019 17:51:19 +0100 Subject: [PATCH 015/127] chore: update jshint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 190993f2f..78a21581d 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "glob": "^7.0.0", "if-node-version": "^1.0.0", "js-beautify": "^1.7.3", - "jshint": "2.9.7", + "jshint": "^2.10.2", "json-schema-test": "^2.0.0", "karma": "^4.0.1", "karma-chrome-launcher": "^2.2.0", From c468632d9c5f98d514938f8c33c76cb7ebd9c0f8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Jul 2019 17:55:14 +0100 Subject: [PATCH 016/127] test: update node.js versions for travis test --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0cfe4295..0f25c1418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,10 @@ before_script: - git submodule update --init - npm install -g codeclimate-test-reporter node_js: - - "6" - "8" - - "9" - "10" + - "11" + - "12" after_script: - codeclimate-test-reporter < coverage/lcov.info - coveralls < coverage/lcov.info From d4765343af76483bd6b6acfdd4206a39b16dc8ba Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sat, 6 Jul 2019 18:06:53 +0100 Subject: [PATCH 017/127] chore(package): update eslint to version 6.0.0 (#1030) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78a21581d..9dadb79b7 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "coveralls": "^3.0.1", "del-cli": "^1.1.0", "dot": "^1.0.3", - "eslint": "^5.0.0", + "eslint": "^6.0.0", "gh-pages-generator": "^0.2.3", "glob": "^7.0.0", "if-node-version": "^1.0.0", From 66c2907470d8a84c22af4d4755fa2bd9fd4b8dab Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sat, 6 Jul 2019 18:12:46 +0100 Subject: [PATCH 018/127] chore(package): update del-cli to version 2.0.0 (#1014) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9dadb79b7..670f8df7d 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "browserify": "^16.2.0", "chai": "^4.0.1", "coveralls": "^3.0.1", - "del-cli": "^1.1.0", + "del-cli": "^2.0.0", "dot": "^1.0.3", "eslint": "^6.0.0", "gh-pages-generator": "^0.2.3", From 8b59052aa517d51c763e5eb8fef51487c7042a91 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Jul 2019 19:02:54 +0100 Subject: [PATCH 019/127] 6.10.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 670f8df7d..bafebbaf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.10.0", + "version": "6.10.1", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From dd827d1c01fd684aa6efa3e52eebc315a6128335 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Jul 2019 19:55:10 +0100 Subject: [PATCH 020/127] label comments (for labelcious) --- .github/ISSUE_TEMPLATE/bug-or-error-report.md | 2 +- .github/config.yml | 28 +++++++++++++++++++ CONTRIBUTING.md | 6 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .github/config.yml diff --git a/.github/ISSUE_TEMPLATE/bug-or-error-report.md b/.github/ISSUE_TEMPLATE/bug-or-error-report.md index 3da68b71e..42c351946 100644 --- a/.github/ISSUE_TEMPLATE/bug-or-error-report.md +++ b/.github/ISSUE_TEMPLATE/bug-or-error-report.md @@ -2,7 +2,7 @@ name: Bug or error report about: Please use for issues related to incorrect validation behaviour title: '' -labels: '' +labels: 'bug report' assignees: '' --- diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 000000000..60b3fab95 --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,28 @@ +# Please supply comments to be used for GitHub labels +githubLabels: + bug: > + Bug confirmed - to be fixed. PR is welcome! + +# duplicate: > +# enhancement: > +# good first issue: > +# help wanted: > +# invalid: > +# question: > +# wont fix: > + + bug report: > + Thank you for the report! If you didn't post a code sample to RunKit yet, + please clone this notebook https://runkit.com/esp/ajv-issue, + post the code sample that demonstrates the bug and post the link here. + It will speed up the investigation and fixing! + + json schema: > + This question is about the usage of JSON Schema specification - it is not specific to Ajv. + Please use JSON Schema reference materials or [submit the question to Stack Overflow](https://stackoverflow.com/questions/ask?tags=jsonschema,ajv). + + - [JSON Schema specification](http://json-schema.org/) + - [Tutorial by Space Telescope Science Institute](http://json-schema.org/understanding-json-schema/) + - [validation keywords](https://github.com/epoberezkin/ajv#validation-keywords) (in Ajv docs) + - [combining schemas](https://github.com/epoberezkin/ajv#ref) (in Ajv docs) + - [Tutorial by @epoberezkin](https://code.tutsplus.com/tutorials/validating-data-with-json-schema-part-1--cms-25343) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 897f63485..eade3b876 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,7 +39,9 @@ Please make sure to include the following information in the issue: 5. Validation result, data AFTER validation, error messages. 6. What results did you expect? -[Create bug report](https://github.com/epoberezkin/ajv/issues/new). +Please include the link to the working code sample at Runkit.com (please clone https://runkit.com/esp/ajv-issue) - it will speed up investigation and fixing. + +[Create bug report](https://github.com/epoberezkin/ajv/issues/new?template=bug-or-error-report.md). #### Change proposals @@ -99,7 +101,7 @@ If nothing helps, please submit: Ajv implements JSON Schema standard draft-04 and draft-06/07. -If it is a general issue related to using the standard keywords included in JSON Schema or implementing some advanced validation logic please ask the question on [Stack Overflow](http://stackoverflow.com/questions/ask?tags=jsonschema,ajv) (my account is [esp](http://stackoverflow.com/users/1816503/esp)) or submitting the question to [JSON-Schema.org](https://github.com/json-schema-org/json-schema-spec/issues/new). Please mention @epoberezkin. +If it is a general issue related to using the standard keywords included in JSON Schema or implementing some advanced validation logic please ask the question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=jsonschema,ajv) (my account is [esp](https://stackoverflow.com/users/1816503/esp)) or submitting the question to [JSON-Schema.org](https://github.com/json-schema-org/json-schema-spec/issues/new). Please mention @epoberezkin. #### Ajv usage questions From 482d2c51df60a3d956bdfedff8f4329c3b91035c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 6 Jul 2019 20:03:57 +0100 Subject: [PATCH 021/127] labels config --- .github/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/config.yml b/.github/config.yml index 60b3fab95..ce9efb997 100644 --- a/.github/config.yml +++ b/.github/config.yml @@ -22,7 +22,11 @@ githubLabels: Please use JSON Schema reference materials or [submit the question to Stack Overflow](https://stackoverflow.com/questions/ask?tags=jsonschema,ajv). - [JSON Schema specification](http://json-schema.org/) + - [Tutorial by Space Telescope Science Institute](http://json-schema.org/understanding-json-schema/) + - [validation keywords](https://github.com/epoberezkin/ajv#validation-keywords) (in Ajv docs) + - [combining schemas](https://github.com/epoberezkin/ajv#ref) (in Ajv docs) + - [Tutorial by @epoberezkin](https://code.tutsplus.com/tutorials/validating-data-with-json-schema-part-1--cms-25343) From d9d6fba7570763d579b29f3c650276e3120f04ed Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 9 Jul 2019 15:29:55 +0100 Subject: [PATCH 022/127] Create FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..bf2439069 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +tidelift: "npm/ajv" From 69802d2de34394e857b026daf1e47c7a22997239 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 10 Jul 2019 14:00:14 +0100 Subject: [PATCH 023/127] security contact --- .github/ISSUE_TEMPLATE.md | 1 + CONTRIBUTING.md | 10 ++++++++++ README.md | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index bac24aca4..ef1c8f934 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -3,6 +3,7 @@ Frequently Asked Questions: https://github.com/epoberezkin/ajv/blob/master/FAQ.m Please provide all info and reduce your schema and data to the smallest possible size. This template is for bug or error reports. For other issues please use: +- security vulnerability: https://tidelift.com/security) - a new feature/improvement: http://epoberezkin.github.io/ajv/contribute.html#changes - browser/compatibility issues: http://epoberezkin.github.io/ajv/contribute.html#compatibility - JSON-Schema standard: http://epoberezkin.github.io/ajv/contribute.html#json-schema diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eade3b876..c509accca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,6 +5,7 @@ Thank you for your help making Ajv better! Every contribution is appreciated. If - [Documentation](#documentation) - [Issues](#issues) - [Bug reports](#bug-reports) + - [Security vulnerabilities](#security-vulnerabilities) - [Change proposals](#changes) - [Browser and compatibility issues](#compatibility) - [Installation and dependency issues](#installation) @@ -44,6 +45,15 @@ Please include the link to the working code sample at Runkit.com (please clone h [Create bug report](https://github.com/epoberezkin/ajv/issues/new?template=bug-or-error-report.md). +#### Security vulnerabilities + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. + +Please do NOT report security vulnerability via GitHub issues. + + #### Change proposals [Create a proposal](https://github.com/epoberezkin/ajv/issues/new?template=change.md) for a new feature, option or some other improvement. diff --git a/README.md b/README.md index 575861e55..eedb2a9a8 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,11 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Defining custom keywords](#defining-custom-keywords) - [Asynchronous schema compilation](#asynchronous-schema-compilation) - [Asynchronous validation](#asynchronous-validation) - - [Security considerations](#security-considerations) +- [Security considerations](#security-considerations) + - [Security contact](#security-contact) + - [Untrusted schemas](#untrusted-schemas) + - [Circular references in objects](#circular-references-in-javascript-objects) + - [Trusted schemas](#security-risks-of-trusted-schemas) - Modifying data during validation - [Filtering data](#filtering-data) - [Assigning defaults](#assigning-defaults) @@ -611,6 +615,13 @@ See [Options](#options). JSON Schema, if properly used, can replace data sanitisation. It doesn't replace other API security considerations. It also introduces additional security aspects to consider. +##### Security contact + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues. + + ##### Untrusted schemas Ajv treats JSON schemas as trusted as your application code. This security model is based on the most common use case, when the schemas are static and bundled together with the application. From d289c38567ed278f516f177d65c69bae7634b07c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 10 Jul 2019 22:09:20 +0100 Subject: [PATCH 024/127] Tidelift subscription --- CONTRIBUTING.md | 2 +- README.md | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c509accca..26f4bf029 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,7 +51,7 @@ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. -Please do NOT report security vulnerability via GitHub issues. +Please do NOT report security vulnerabilities via GitHub issues. #### Change proposals diff --git a/README.md b/README.md index eedb2a9a8..1fea1e4f6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Greenkeeper badge](https://badges.greenkeeper.io/epoberezkin/ajv.svg)](https://greenkeeper.io/) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) -### _Ajv and [related repositories](#related-packages) will be transfered to [ajv-validator](https://github.com/ajv-validator) org_ ## Using version 6 @@ -69,7 +68,7 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Plugins](#plugins) - [Related packages](#related-packages) - [Some packages using Ajv](#some-packages-using-ajv) -- [Tests, Contributing, History, License](#tests) +- [Tests, Contributing, History, Support, License](#tests) ## Performance @@ -619,7 +618,7 @@ JSON Schema, if properly used, can replace data sanitisation. It doesn't replace To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). -Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues. +Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerabilities via GitHub issues. ##### Untrusted schemas @@ -1350,6 +1349,11 @@ __Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/r [Version 2.0.0](https://github.com/epoberezkin/ajv/releases/tag/2.0.0). +## Open-source software support + +Ajv is a part of [Tidelift subscription]((https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme)) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. + + ## License [MIT](https://github.com/epoberezkin/ajv/blob/master/LICENSE) From 669bf96c79a1aa425b6cc42dcb10c8c62b8869c9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 10 Jul 2019 22:10:22 +0100 Subject: [PATCH 025/127] readme: fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fea1e4f6..cafbd71c9 100644 --- a/README.md +++ b/README.md @@ -1351,7 +1351,7 @@ __Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/r ## Open-source software support -Ajv is a part of [Tidelift subscription]((https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme)) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. +Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. ## License From 53b5682cb7a28f686b05842fa1ea3dea71fea870 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 13 Jul 2019 21:38:44 +0100 Subject: [PATCH 026/127] fix: the unknown keyword in the schema without known keywords inside compound schema (e.g. anyOf) is ignored with strictKeywords option --- lib/dot/definitions.def | 4 +++- spec/options/strictKeywords.spec.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dot/definitions.def b/lib/dot/definitions.def index cdbe140bb..b68e064e8 100644 --- a/lib/dot/definitions.def +++ b/lib/dot/definitions.def @@ -63,7 +63,9 @@ {{## def.nonEmptySchema:_schema: - it.util.schemaHasRules(_schema, it.RULES.all) + (it.opts.strictKeywords + ? typeof _schema == 'object' && Object.keys(_schema).length > 0 + : it.util.schemaHasRules(_schema, it.RULES.all)) #}} diff --git a/spec/options/strictKeywords.spec.js b/spec/options/strictKeywords.spec.js index b212d15c7..4895b78e4 100644 --- a/spec/options/strictKeywords.spec.js +++ b/spec/options/strictKeywords.spec.js @@ -49,6 +49,19 @@ describe('strictKeywords option', function() { }); }); + describe('unknown keyword inside schema that has no known keyword in compound keyword', function() { + it('should throw an error given an unknown keyword when strictKeywords is true', function() { + var ajv = new Ajv({strictKeywords: true}); + var schema = { + anyOf: [ + { + unknownKeyword: 1 + } + ] + }; + should.throw(function() { ajv.compile(schema); }); + }); + }); function getLogger(output) { return { From 6e4a3464b935053c0a5b65fa27db454367d23b2b Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 14 Jul 2019 14:38:33 +0100 Subject: [PATCH 027/127] 6.10.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bafebbaf3..ca9f7c93f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.10.1", + "version": "6.10.2", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From 098e1d2a25094eb3dfa0481a6fb73f4330a6b5c0 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 14 Jul 2019 18:32:12 +0100 Subject: [PATCH 028/127] Update FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index bf2439069..c77c8e485 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ tidelift: "npm/ajv" +open_collective: "ajv" From 1163e1a0891491dd63b213705bf3ac02e2c486b6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 19 Jul 2019 06:35:08 +0100 Subject: [PATCH 029/127] docs: regexp considerations (#1047) --- README.md | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cafbd71c9..1dc099d73 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Untrusted schemas](#untrusted-schemas) - [Circular references in objects](#circular-references-in-javascript-objects) - [Trusted schemas](#security-risks-of-trusted-schemas) + - [ReDoS attack](#redos-attack) - Modifying data during validation - [Filtering data](#filtering-data) - [Assigning defaults](#assigning-defaults) @@ -240,7 +241,11 @@ __Please note__: Ajv does not implement validation of the keywords `examples`, ## Formats -The following formats are supported for string validation with "format" keyword: +Ajv implements formats defined by JSON Schema specification and several other formats. It is recommended NOT to use "format" keyword implementations with untrusted data, as they use potentially unsafe regular expressions - see [ReDoS attack](#redos-attack). + +__Please note__: if you need to use "format" keyword to validate untrusted data, you MUST assess their suitability and safety for your validation scenarios. + +The following formats are implemented for string validation with "format" keyword: - _date_: full-date according to [RFC3339](http://tools.ietf.org/html/rfc3339#section-5.6). - _time_: time with optional time-zone. @@ -646,9 +651,9 @@ An attempt to compile such schemas or validate such data would cause stack overf Some keywords in JSON Schemas can lead to very slow validation for certain data. These keywords include (but may be not limited to): -- `pattern` and `format` for large strings - use `maxLength` to mitigate +- `pattern` and `format` for large strings - in some cases using `maxLength` can help mitigate it, but certain regular expressions can lead to exponential validation time even with relatively short strings (see [ReDoS attack](#redos-attack)). +- `patternProperties` for large property names - use `propertyNames` to mitigate, but some regular expressions can have exponential evaluation time as well. - `uniqueItems` for large non-scalar arrays - use `maxItems` to mitigate -- `patternProperties` for large property names - use `propertyNames` to mitigate __Please note__: The suggestions above to prevent slow validation would only work if you do NOT use `allErrors: true` in production code (using it would continue validation after validation errors). @@ -660,13 +665,29 @@ const isSchemaSecure = ajv.compile(require('ajv/lib/refs/json-schema-secure.json const schema1 = {format: 'email'}; isSchemaSecure(schema1); // false -const schema2 = {format: 'email', maxLength: 256}; +const schema2 = {format: 'email', maxLength: MAX_LENGTH}; isSchemaSecure(schema2); // true ``` __Please note__: following all these recommendation is not a guarantee that validation of untrusted data is safe - it can still lead to some undesirable results. +## ReDoS attack + +Certain regular expressions can lead to the exponential evaluation time even with relatively short strings. + +Please assess the regular expressions you use in the schemas on their vulnerability to this attack - see [safe-regex](https://github.com/substack/safe-regex), for example. + +__Please note__: some formats that Ajv implements use [regular expressions](https://github.com/epoberezkin/ajv/blob/master/lib/compile/formats.js) that can be vulnerable to ReDoS attack, so if you use Ajv to validate data from untrusted sources __it is strongly recommended__ to consider the following: + +- making assessment of "format" implementations in Ajv. +- using `format: 'fast'` option that simplifies some of the regular expressions (although it does not guarantee that they are safe). +- replacing format implementations provided by Ajv with your own implementations of "format" keyword that either uses different regular expressions or another approach to format validation. +- disabling format validation by ignoring "format" keyword with option `format: false` + +Whatever mitigation you choose, please assume all formats provided by Ajv as potentially unsafe and make your own assessment of their suitability for your validation scenarios. + + ## Filtering data With [option `removeAdditional`](#options) (added by [andyscott](https://github.com/andyscott)) you can filter data during the validation. From db94b118d41fbc81c3d7ab605b94c4d15dc89af8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Fri, 19 Jul 2019 06:39:20 +0100 Subject: [PATCH 030/127] docs: regexp considerations addition --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dc099d73..d645c3f70 100644 --- a/README.md +++ b/README.md @@ -682,7 +682,7 @@ __Please note__: some formats that Ajv implements use [regular expressions](http - making assessment of "format" implementations in Ajv. - using `format: 'fast'` option that simplifies some of the regular expressions (although it does not guarantee that they are safe). -- replacing format implementations provided by Ajv with your own implementations of "format" keyword that either uses different regular expressions or another approach to format validation. +- replacing format implementations provided by Ajv with your own implementations of "format" keyword that either uses different regular expressions or another approach to format validation. Please see [addFormat](#api-addformat) method. - disabling format validation by ignoring "format" keyword with option `format: false` Whatever mitigation you choose, please assume all formats provided by Ajv as potentially unsafe and make your own assessment of their suitability for your validation scenarios. From 82112b089a079f3d889b02eddf0144cc7d2330a3 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Fri, 19 Jul 2019 21:12:20 +0100 Subject: [PATCH 031/127] chore(package): update karma-chrome-launcher to version 3.0.0 (#1043) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ca9f7c93f..5c3dfc746 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "jshint": "^2.10.2", "json-schema-test": "^2.0.0", "karma": "^4.0.1", - "karma-chrome-launcher": "^2.2.0", + "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", "mocha": "^6.0.0", From 382c2b9ed151287e4ff0f233d689563f90cd5c20 Mon Sep 17 00:00:00 2001 From: Christian Pillsbury Date: Thu, 15 Aug 2019 11:30:07 -0500 Subject: [PATCH 032/127] Issue #1061 - Update time and date-time format definitions to support two digit and colon-less variants of timezone offset. Add tests. Update test eslint to include global after function. --- lib/compile/formats.js | 6 +- spec/.eslintrc.yml | 1 + .../issues/1061_alternative_time_offsets.json | 74 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 spec/tests/issues/1061_alternative_time_offsets.json diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 5c0fb9ef5..d06792aa4 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -4,7 +4,7 @@ var util = require('./util'); var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; -var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i; +var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i; var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; @@ -33,8 +33,8 @@ formats.fast = { // date: http://tools.ietf.org/html/rfc3339#section-5.6 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/, // date-time: http://tools.ietf.org/html/rfc3339#section-5.6 - time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i, - 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i, + time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, + 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js uri: /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i, 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, diff --git a/spec/.eslintrc.yml b/spec/.eslintrc.yml index f9c66d538..543e6eec9 100644 --- a/spec/.eslintrc.yml +++ b/spec/.eslintrc.yml @@ -7,5 +7,6 @@ globals: describe: false it: false before: false + after: false beforeEach: false afterEach: false diff --git a/spec/tests/issues/1061_alternative_time_offsets.json b/spec/tests/issues/1061_alternative_time_offsets.json new file mode 100644 index 000000000..bf80f9581 --- /dev/null +++ b/spec/tests/issues/1061_alternative_time_offsets.json @@ -0,0 +1,74 @@ +[ + { + "description": "Support for alternative ISO-8601 timezone offset formats (#1061)", + "schema": {"format": "date-time"}, + "tests": [ + { + "description": "valid positiive two digit", + "data": "2016-01-31T02:31:17+01", + "valid": true + }, + { + "description": "valid negative two digit", + "data": "2016-01-31T02:31:17-01", + "valid": true + }, + { + "description": "valid positiive four digit no colon", + "data": "2016-01-31T02:31:17+0130", + "valid": true + }, + { + "description": "valid negative four digit no colon", + "data": "2016-01-31T02:31:17-0130", + "valid": true + }, + { + "description": "invalid positiive three digit no colon", + "data": "2016-01-31T02:31:17+013", + "valid": false + }, + { + "description": "invalid negative three digit no colon", + "data": "2016-01-31T02:31:17-013", + "valid": false + } + ] + }, + { + "description": "Support for alternative ISO-8601 timezone offset formats (#1061)", + "schema": {"format": "time"}, + "tests": [ + { + "description": "valid positiive two digit", + "data": "02:31:17+01", + "valid": true + }, + { + "description": "valid negative two digit", + "data": "02:31:17-01", + "valid": true + }, + { + "description": "valid positiive four digit no colon", + "data": "02:31:17+0130", + "valid": true + }, + { + "description": "valid negative four digit no colon", + "data": "02:31:17-0130", + "valid": true + }, + { + "description": "invalid positiive three digit no colon", + "data": "02:31:17+013", + "valid": false + }, + { + "description": "invalid negative three digit no colon", + "data": "02:31:17-013", + "valid": false + } + ] + } +] From 608545c0d24ff45477ebede06e0fba0e188396fe Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 11 Sep 2019 14:36:21 +0100 Subject: [PATCH 033/127] revert eslint change --- spec/.eslintrc.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/.eslintrc.yml b/spec/.eslintrc.yml index 543e6eec9..f9c66d538 100644 --- a/spec/.eslintrc.yml +++ b/spec/.eslintrc.yml @@ -7,6 +7,5 @@ globals: describe: false it: false before: false - after: false beforeEach: false afterEach: false From 7f6ae8c4a2a057c3dfb924d1d46ded3c7758e56b Mon Sep 17 00:00:00 2001 From: Jess Date: Tue, 17 Sep 2019 17:53:41 -0700 Subject: [PATCH 034/127] Added financial contributors to the README --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d645c3f70..be013ebb0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/07. [![Build Status](https://travis-ci.org/epoberezkin/ajv.svg?branch=master)](https://travis-ci.org/epoberezkin/ajv) -[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) +[![Financial Contributors on Open Collective](https://opencollective.com/ajv/all/badge.svg?label=financial+contributors)](https://opencollective.com/ajv) [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) [![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/epoberezkin/ajv.svg)](https://greenkeeper.io/) @@ -1375,6 +1375,36 @@ __Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/r Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. +## Contributors + +### Code Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + +### Financial Contributors + +Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/ajv/contribute)] + +#### Individuals + + + +#### Organizations + +Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/ajv/contribute)] + + + + + + + + + + + + ## License [MIT](https://github.com/epoberezkin/ajv/blob/master/LICENSE) From 68b00801222c2fe2d77709929a3558bac4562f60 Mon Sep 17 00:00:00 2001 From: Jess Date: Tue, 17 Sep 2019 17:53:41 -0700 Subject: [PATCH 035/127] Added call to donate after npm install (optional) --- package.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5c3dfc746..c2f5240d8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "test-all": "npm run test-ts && npm run test-cov && if-node-version 10 npm run test-browser", "test": "npm run lint && npm run build && npm run test-all", "prepublish": "npm run build && npm run bundle", - "watch": "watch \"npm run build\" ./lib/dot" + "watch": "watch \"npm run build\" ./lib/dot", + "postinstall": "opencollective-postinstall || true" }, "nyc": { "exclude": [ @@ -65,6 +66,7 @@ "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", + "opencollective-postinstall": "^2.0.2", "uri-js": "^4.2.2" }, "devDependencies": { @@ -94,5 +96,9 @@ "typescript": "^2.8.3", "uglify-js": "^3.3.24", "watch": "^1.0.0" + }, + "collective": { + "type": "opencollective", + "url": "https://opencollective.com/ajv" } -} +} \ No newline at end of file From 7b574e764b4b9065308c6b98d948a7e3e16fa19a Mon Sep 17 00:00:00 2001 From: Dominik Broj <19861998+thetric@users.noreply.github.com> Date: Tue, 24 Sep 2019 10:12:16 +0200 Subject: [PATCH 036/127] docs(readme): add usage notes for TypeScript users --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index d645c3f70..845481207 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,11 @@ Try it in the Node.js REPL: https://tonicdev.com/npm/ajv The fastest validation call: ```javascript +// Node.js require: var Ajv = require('ajv'); +// or ESM/TypeScript import +import Ajv from 'ajv'; + var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} var validate = ajv.compile(schema); var valid = validate(data); @@ -165,6 +169,10 @@ The best performance is achieved when using compiled functions returned by `comp __Please note__: every time a validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors) +__Note for TypeScript users__: `ajv` provides its own TypeScript declarations +out of the box, so you don't need to install the deprecated `@types/ajv` +module. + ## Using in browser From 4e240b78f2387577f860e6af3c2c9f0ae6e8ba31 Mon Sep 17 00:00:00 2001 From: cjancsar <51799534+cjancsar@users.noreply.github.com> Date: Tue, 29 Oct 2019 13:50:09 -0400 Subject: [PATCH 037/127] Update FAQ.md (#1115) - Fix type "sence" to "sense" --- FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index 472a5edb0..36ac967cd 100644 --- a/FAQ.md +++ b/FAQ.md @@ -83,7 +83,7 @@ There are several ways to implement the described logic that would allow two pro ##### Why the validation fails when I use option `removeAdditional` with the keyword `anyOf`/etc.? -This problem is related to the problem explained above - properties treated as additional in the sence of `additionalProperties` keyword, based on `properties`/`patternProperties` keyword in the same schema object. +This problem is related to the problem explained above - properties treated as additional in the sense of `additionalProperties` keyword, based on `properties`/`patternProperties` keyword in the same schema object. See the exemple in [Filtering Data](https://github.com/epoberezkin/ajv#filtering-data) section of readme. From 25266ef7c277754225333de33f2ee56556f3c377 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 24 Nov 2019 10:57:22 +0000 Subject: [PATCH 038/127] docs: typescript issue template --- .github/ISSUE_TEMPLATE/typescript.md | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/typescript.md diff --git a/.github/ISSUE_TEMPLATE/typescript.md b/.github/ISSUE_TEMPLATE/typescript.md new file mode 100644 index 000000000..7385349b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/typescript.md @@ -0,0 +1,42 @@ +--- +name: Missing or incorrect type definition +about: Please use for issues related to typescript types +title: '' +labels: 'typescript' +assignees: '' + +--- + + + +**What version of Ajv are you using? Does the issue happen if you use the latest version?** + + +**Your typescript code** + + + +```typescript + + +``` + + +**Typescript compiler error messages** + +``` + + +``` + +**Describe the change that should be made to address the issue?** + + +**Are you going to resolve the issue?** From 4e56bf6268aea25c6632ba52ea602d3ff7ee641d Mon Sep 17 00:00:00 2001 From: Leonardo Villela Date: Sun, 24 Nov 2019 11:01:27 +0000 Subject: [PATCH 039/127] Add dataPathArr to CompilationContext interface type definition (#1114) --- lib/ajv.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 5e7cfa7da..ba75f8d2d 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -243,6 +243,7 @@ declare namespace ajv { interface CompilationContext { level: number; dataLevel: number; + dataPathArr: string[]; schema: any; schemaPath: string; baseId: string; From 0e542bdcd6cc12c98513cf475928520fae32a00d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sun, 24 Nov 2019 11:09:54 +0000 Subject: [PATCH 040/127] chore(package): update del-cli to version 3.0.0 (#1084) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c3dfc746..b517e6e8a 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "browserify": "^16.2.0", "chai": "^4.0.1", "coveralls": "^3.0.1", - "del-cli": "^2.0.0", + "del-cli": "^3.0.0", "dot": "^1.0.3", "eslint": "^6.0.0", "gh-pages-generator": "^0.2.3", From 8c4671473cf1b92c609bb01aad981d632b6d7066 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 24 Nov 2019 11:40:48 +0000 Subject: [PATCH 041/127] chore(package): update uglify-js to version 3.6.9 (#1125) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b517e6e8a..54eec94c0 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "pre-commit": "^1.1.1", "require-globify": "^1.3.0", "typescript": "^2.8.3", - "uglify-js": "^3.3.24", + "uglify-js": "^3.6.9", "watch": "^1.0.0" } } From d705f8e1e55d719cdc6c70ef89fd574616ce0b84 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 14 Dec 2019 16:21:22 +0000 Subject: [PATCH 042/127] fix(package): update fast-deep-equal to version 3.1.1 (#1135) Closes #1129 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 54eec94c0..6f15e2dd0 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "homepage": "https://github.com/epoberezkin/ajv", "tonicExampleFilename": ".tonic_example.js", "dependencies": { - "fast-deep-equal": "^2.0.1", + "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" From f7beda09e7bf76b3d3e8f631cba8a9577fdc344a Mon Sep 17 00:00:00 2001 From: sambauers Date: Wed, 8 Jan 2020 10:59:21 +1100 Subject: [PATCH 043/127] Improved hostname validation. Allow trailing dot. Check for octet count rather than string length. --- lib/compile/formats.js | 13 ++++++++++-- spec/tests/rules/format.json | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index d06792aa4..a5001c7b6 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -5,7 +5,7 @@ var util = require('./util'); var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i; -var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i; +var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; // uri-template: https://tools.ietf.org/html/rfc6570 @@ -126,7 +126,16 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - return str.length <= 255 && HOSTNAME.test(str); + + // Count octets, not string length + // https://devblogs.microsoft.com/oldnewthing/?p=7873 + var count = str.length; + // Do not count trailing dot if present + if (/\.$/.test(str)) count--; + // Add leading and trailing "length octets" to count + count += 2; + + return count <= 255 && HOSTNAME.test(str); } diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index 226608bd4..e4b492dc6 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -82,10 +82,50 @@ "data": "123.example.com", "valid": true }, + { + "description": "valid hostname - trailing dot", + "data": "123.example.com.", + "valid": true + }, + { + "description": "valid hostname - single label", + "data": "localhost", + "valid": true + }, + { + "description": "valid hostname - single label with trailing dot", + "data": "localhost.", + "valid": true + }, { "description": "valid hostname #312", "data": "lead-routing-qa.lvuucj.0001.use1.cache.amazonaws.com", "valid": true + }, + { + "description": "valid hostname - maximum length label (63 chars)", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.example.com", + "valid": true + }, + { + "description": "invalid hostname - label too long (64 chars)", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.example.com", + "valid": false + }, + { + "description": "valid hostname - maximum length hostname (255 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxy.example.com", + "valid": true + }, + { + "description": "valid hostname - maximum length hostname (255 octets) with trailing dot", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxy.example.com.", + "valid": true + }, + { + "description": "invalid hostname - hostname too long (256 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com.", + "valid": false } ] }, From c3bbc3e35b09ba9ef5a2b6a4501c7b9812636d49 Mon Sep 17 00:00:00 2001 From: sambauers Date: Thu, 9 Jan 2020 11:52:52 +1100 Subject: [PATCH 044/127] More efficient hostname function. --- lib/compile/formats.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index a5001c7b6..429a1f29e 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -126,16 +126,15 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 + if (!HOSTNAME.test(str)) return false; // Count octets, not string length // https://devblogs.microsoft.com/oldnewthing/?p=7873 - var count = str.length; + var octets = str.length; // Do not count trailing dot if present - if (/\.$/.test(str)) count--; - // Add leading and trailing "length octets" to count - count += 2; - - return count <= 255 && HOSTNAME.test(str); + if (/\.$/.test(str)) octets--; + // With starting and ending length octets this would be 255, not 253 + return octets <= 253; } From 508f640e640b1a404af3e1fe3c98776c0e05b302 Mon Sep 17 00:00:00 2001 From: sambauers Date: Thu, 9 Jan 2020 12:11:23 +1100 Subject: [PATCH 045/127] More terse hostname function. --- lib/compile/formats.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 429a1f29e..f51a3b76f 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -126,15 +126,11 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - if (!HOSTNAME.test(str)) return false; - // Count octets, not string length // https://devblogs.microsoft.com/oldnewthing/?p=7873 - var octets = str.length; - // Do not count trailing dot if present - if (/\.$/.test(str)) octets--; + // Count octets, not string length (remove any trailing dot) // With starting and ending length octets this would be 255, not 253 - return octets <= 253; + return str.replace(/\.$/, '').length <= 253 && HOSTNAME.test(str); } From cc97b003f59db096171263a9ca6cf58936b3bc07 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Sat, 18 Jan 2020 08:07:05 +0000 Subject: [PATCH 046/127] chore(package): update nyc to version 15.0.0 (#1139) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f15e2dd0..109e47663 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", "mocha": "^6.0.0", - "nyc": "^14.0.0", + "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", "typescript": "^2.8.3", From f38f2e4136c790b409b12528dd6acd51283654ab Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Jan 2020 08:53:51 +0000 Subject: [PATCH 047/127] test: remove failing typescript test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 109e47663..43479a6e8 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build": "del-cli lib/dotjs/*.js \"!lib/dotjs/index.js\" && node scripts/compile-dots.js", "test-karma": "karma start", "test-browser": "del-cli .browser && npm run bundle && scripts/prepare-tests && npm run test-karma", - "test-all": "npm run test-ts && npm run test-cov && if-node-version 10 npm run test-browser", + "test-all": "npm run test-cov && if-node-version 10 npm run test-browser", "test": "npm run lint && npm run build && npm run test-all", "prepublish": "npm run build && npm run bundle", "watch": "watch \"npm run build\" ./lib/dot" From 03198c2b6d52ec5eb7ffbf7623f05db5372689a1 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Jan 2020 09:00:24 +0000 Subject: [PATCH 048/127] 6.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43479a6e8..da9218a83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.10.2", + "version": "6.11.0", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From d9661b442e02077bc355af554a9e7c61e6390763 Mon Sep 17 00:00:00 2001 From: sambauers Date: Wed, 22 Jan 2020 12:46:58 +1100 Subject: [PATCH 049/127] Do hostname character count in regexp. --- lib/compile/formats.js | 8 +++----- spec/tests/rules/format.json | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index f51a3b76f..0e6e910fa 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -5,7 +5,7 @@ var util = require('./util'); var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31]; var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i; -var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; +var HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i; var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; // uri-template: https://tools.ietf.org/html/rfc6570 @@ -126,11 +126,9 @@ function date_time(str) { function hostname(str) { // https://tools.ietf.org/html/rfc1034#section-3.5 // https://tools.ietf.org/html/rfc1123#section-2 - // https://devblogs.microsoft.com/oldnewthing/?p=7873 - // Count octets, not string length (remove any trailing dot) - // With starting and ending length octets this would be 255, not 253 - return str.replace(/\.$/, '').length <= 253 && HOSTNAME.test(str); + // https://tools.ietf.org/html/rfc1034#section-3.1 + return HOSTNAME.test(str); } diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index e4b492dc6..c316a6ee5 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -124,6 +124,11 @@ }, { "description": "invalid hostname - hostname too long (256 octets)", + "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com", + "valid": false + }, + { + "description": "invalid hostname - hostname too long (256 octets) with trailing dot", "data": "abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.example.com.", "valid": false } From d3488073b16c54704bc10f7d89645b34c49b0204 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Tue, 4 Feb 2020 10:09:47 -0500 Subject: [PATCH 050/127] Add custom logger example The current value description for the custom logger option is not easily understandable. Adding an example to this would be greatly beneficial. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d645c3f70..641a6a4de 100644 --- a/README.md +++ b/README.md @@ -1151,6 +1151,15 @@ Defaults: - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. + ```javascript + var ajv = new AJV.default({ + logger: { + log: log => console.log(log), + warn: () => null, + error: error => console.error(error), + }, + }); + ``` - `false` - logging is disabled. From 23ebb55c1ae8ef69bc464fd6a8e142e9b6ad813c Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Tue, 11 Feb 2020 09:58:45 +0200 Subject: [PATCH 051/127] fix(types) added undefined to getSchema() --- lib/ajv.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index ba75f8d2d..c946096ad 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -80,9 +80,9 @@ declare namespace ajv { /** * Get compiled schema from the instance by `key` or `ref`. * @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id). - * @return {Function} schema validating function (with property `schema`). + * @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema. */ - getSchema(keyRef: string): ValidateFunction; + getSchema(keyRef: string): ValidateFunction | undefined; /** * Remove cached schema(s). * If no parameter is passed all schemas but meta-schemas are removed. From 10f6cba4c561fdea1b762156b4823d0826db818e Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2020 08:27:54 +0000 Subject: [PATCH 052/127] chore(package): update mocha to version 7.0.1 (#1156) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da9218a83..5cfec97d2 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", - "mocha": "^6.0.0", + "mocha": "^7.0.1", "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", From 5a92f70f5f967d80e4599775dfc2c0b8647c1b23 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Tue, 11 Feb 2020 10:58:20 -0500 Subject: [PATCH 053/127] Adjusting Example - Converting example to ES5 - Updating example to conform to other examples - Updating example to have custom warning message --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 641a6a4de..cfa23b667 100644 --- a/README.md +++ b/README.md @@ -1152,12 +1152,18 @@ Defaults: - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. ```javascript - var ajv = new AJV.default({ + var ajv = new Ajv({ logger: { - log: log => console.log(log), - warn: () => null, - error: error => console.error(error), - }, + log: function log(_log) { + return console.log(_log); + }, + warn: function warn(_warn) { + return console.warn("Custom Warning: ".concat(_warn)); + }, + error: function error(_error) { + return console.error(_error); + } + } }); ``` - `false` - logging is disabled. From d601e4856421f87c08c68abf45bc1d8397c5c47b Mon Sep 17 00:00:00 2001 From: Matti Manninen Date: Wed, 12 Feb 2020 16:27:07 +0200 Subject: [PATCH 054/127] Fixed the TypeScript type definition for Options' "format" --- lib/ajv.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index c946096ad..29cdee59a 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -169,7 +169,7 @@ declare namespace ajv { jsonPointers?: boolean; uniqueItems?: boolean; unicode?: boolean; - format?: string; + format?: false | string; formats?: object; unknownFormats?: true | string[] | 'ignore'; schemas?: Array | object; From d127103db174ebb09a8a59143d335e54d343afb2 Mon Sep 17 00:00:00 2001 From: RadiationSickness Date: Wed, 12 Feb 2020 10:29:29 -0500 Subject: [PATCH 055/127] Move Logging Sample To Error Section Updated and moved logging sample to new Error Logging subsection --- README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cfa23b667..41d703dc8 100644 --- a/README.md +++ b/README.md @@ -1151,21 +1151,6 @@ Defaults: - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. - _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. - ```javascript - var ajv = new Ajv({ - logger: { - log: function log(_log) { - return console.log(_log); - }, - warn: function warn(_warn) { - return console.warn("Custom Warning: ".concat(_warn)); - }, - error: function error(_error) { - return console.error(_error); - } - } - }); - ``` - `false` - logging is disabled. @@ -1302,6 +1287,30 @@ Properties of `params` object in errors depend on the keyword that failed valida - custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name). +### Error Logging + +Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown. +- **Required Methods**: `log`, `warn`, `error` + +```javascript +var otherLogger = new OtherLogger(); +var ajv = new Ajv({ + logger: { + log: function log(_log) { + return console.log(_log); + }, + warn: function warn(_warn) { + return otherLogger.logWarn(_warn); + }, + error: function error(_error) { + otherLogger.logError(_error); + return console.error(_error); + } + } +}); +``` + + ## Plugins Ajv can be extended with plugins that add custom keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions: From 46171d295dda49b6f68365665bbe8dedd34b6a66 Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:16:31 +0000 Subject: [PATCH 056/127] Add keywords to ajv options --- lib/ajv.d.ts | 4 ++++ lib/ajv.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index 29cdee59a..cb600e168 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -171,6 +171,7 @@ declare namespace ajv { unicode?: boolean; format?: false | string; formats?: object; + keywords?: object; unknownFormats?: true | string[] | 'ignore'; schemas?: Array | object; schemaId?: '$id' | 'id' | 'auto'; @@ -252,6 +253,9 @@ declare namespace ajv { formats: { [index: string]: FormatDefinition | undefined; }; + keywords: { + [index: string]: KeywordDefinition | undefined; + }; compositeRule: boolean; validate: (schema: object) => boolean; util: { diff --git a/lib/ajv.js b/lib/ajv.js index 611b93835..06a45b650 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -69,6 +69,7 @@ function Ajv(opts) { this._metaOpts = getMetaSchemaOptions(this); if (opts.formats) addInitialFormats(this); + if (opts.keywords) addInitialKeywords(this); addDefaultMetaSchema(this); if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta); if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}}); @@ -467,6 +468,14 @@ function addInitialFormats(self) { } +function addInitialKeywords(self) { + for (var name in self._opts.keywords) { + var keyword = self._opts.keywords[name]; + self.addKeyword(name, keyword); + } +} + + function checkUnique(self, id) { if (self._schemas[id] || self._refs[id]) throw new Error('schema with key or id "' + id + '" already exists'); From 4d9dd8c2a69ef97949720bef50ba85074f0c9909 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 16 Feb 2020 22:24:10 +0000 Subject: [PATCH 057/127] docs: link to $data reference proposal, closes #51 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d645c3f70..5569828aa 100644 --- a/README.md +++ b/README.md @@ -328,7 +328,7 @@ __Please note__: ## $data reference -With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema/json-schema/wiki/$data-(v5-proposal)) for more information about how it works. +With `$data` option you can use values from the validated data as the values for the schema keywords. See [proposal](https://github.com/json-schema-org/json-schema-spec/issues/51) for more information about how it works. `$data` reference is supported in the keywords: const, enum, format, maximum/minimum, exclusiveMaximum / exclusiveMinimum, maxLength / minLength, maxItems / minItems, maxProperties / minProperties, formatMaximum / formatMinimum, formatExclusiveMaximum / formatExclusiveMinimum, multipleOf, pattern, required, uniqueItems. From 120748cc6cfa2366167b2da93ad34d1db69088fc Mon Sep 17 00:00:00 2001 From: sambauers Date: Mon, 17 Feb 2020 10:23:34 +1100 Subject: [PATCH 058/127] Only use regex for hostname checks. --- lib/compile/formats.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 0e6e910fa..44895b0b4 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -70,7 +70,7 @@ formats.full = { 'uri-template': URITEMPLATE, url: URL, email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i, - hostname: hostname, + hostname: HOSTNAME, ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i, regex: regex, @@ -123,15 +123,6 @@ function date_time(str) { } -function hostname(str) { - // https://tools.ietf.org/html/rfc1034#section-3.5 - // https://tools.ietf.org/html/rfc1123#section-2 - // https://devblogs.microsoft.com/oldnewthing/?p=7873 - // https://tools.ietf.org/html/rfc1034#section-3.1 - return HOSTNAME.test(str); -} - - var NOT_URI_FRAGMENT = /\/|:/; function uri(str) { // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "." From f94db48984da812306acd8c080778807af514ede Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:16:56 +0000 Subject: [PATCH 059/127] Update options validation spec --- spec/options/options_validation.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/options/options_validation.spec.js b/spec/options/options_validation.spec.js index e362826bc..3f86b2fc7 100644 --- a/spec/options/options_validation.spec.js +++ b/spec/options/options_validation.spec.js @@ -26,12 +26,35 @@ describe('validation options', function() { }}); var validate = ajv.compile({ format: 'identifier' }); + validate('Abc1') .should.equal(true); validate('123') .should.equal(false); validate(123) .should.equal(true); }); }); + describe('keywords', function() { + it('should add keywords from options', function() { + var ajv = new Ajv({ keywords: { + string: { + validate: function (schema, data ) { + + console.log(">>", data); + return /^[a-z_$][a-z0-9_$]*$/i.test(data); + } + } + }}); + + var validate = ajv.compile({ string: true }); + + validate('Abc1') .should.equal(true); + validate('foo bar').should.equal(false); + validate('123').should.equal(false); + validate(123).should.equal(false); + validate(123).should.equal(false); + }); + }); + describe('uniqueItems', function() { it('should not validate uniqueItems with uniqueItems option == false', function() { From 38191c2693ccb06ab2d79b24c6ca9aa29a4d2c03 Mon Sep 17 00:00:00 2001 From: Francisco Morais <35690067+franciscomorais@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:17:10 +0000 Subject: [PATCH 060/127] Update readme with keywords option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d645c3f70..cc6992d4d 100644 --- a/README.md +++ b/README.md @@ -1144,6 +1144,7 @@ Defaults: - `"full"` - more restrictive and slow validation. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode. - `false` - ignore all format keywords. - _formats_: an object with custom formats. Keys and values will be passed to `addFormat` method. +- _keywords_: an object with custom keywords. Keys and values will be passed to `addKeyword` method. - _unknownFormats_: handling of unknown formats. Option values: - `true` (default) - if an unknown format is encountered the exception is thrown during schema compilation. If `format` keyword value is [$data reference](#data-reference) and it is unknown the validation will fail. - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail. From e5bed30f2a057227ec4c256588906e220c4c302b Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:14:51 +0000 Subject: [PATCH 061/127] test: update option keywords test --- spec/options/options_validation.spec.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/options/options_validation.spec.js b/spec/options/options_validation.spec.js index 3f86b2fc7..950a0c289 100644 --- a/spec/options/options_validation.spec.js +++ b/spec/options/options_validation.spec.js @@ -28,6 +28,7 @@ describe('validation options', function() { var validate = ajv.compile({ format: 'identifier' }); validate('Abc1') .should.equal(true); + validate('foo bar') .should.equal(false); validate('123') .should.equal(false); validate(123) .should.equal(true); }); @@ -36,22 +37,20 @@ describe('validation options', function() { describe('keywords', function() { it('should add keywords from options', function() { var ajv = new Ajv({ keywords: { - string: { + identifier: { + type: 'string', validate: function (schema, data ) { - - console.log(">>", data); return /^[a-z_$][a-z0-9_$]*$/i.test(data); } } }}); - var validate = ajv.compile({ string: true }); + var validate = ajv.compile({ identifier: true }); validate('Abc1') .should.equal(true); - validate('foo bar').should.equal(false); - validate('123').should.equal(false); - validate(123).should.equal(false); - validate(123).should.equal(false); + validate('foo bar') .should.equal(false); + validate('123') .should.equal(false); + validate(123) .should.equal(true); }); }); From 0163e5c233bc9d6d2795cd498719c568d4a8653a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:29:55 +0000 Subject: [PATCH 062/127] docs: error logging code sample --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bc245a313..9bd1f5718 100644 --- a/README.md +++ b/README.md @@ -1158,7 +1158,7 @@ Defaults: - `[String]` - an array of unknown format names that will be ignored. This option can be used to allow usage of third party schemas with format(s) for which you don't have definitions, but still fail if another unknown format is used. If `format` keyword value is [$data reference](#data-reference) and it is not in this array the validation will fail. - `"ignore"` - to log warning during schema compilation and always pass validation (the default behaviour in versions before 5.0.0). This option is not recommended, as it allows to mistype format name and it won't be validated without any error message. This behaviour is required by JSON Schema specification. - _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object. -- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values: +- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. See [Error logging](#error-logging). Option values: - custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown. - `false` - logging is disabled. @@ -1296,7 +1296,7 @@ Properties of `params` object in errors depend on the keyword that failed valida - custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name). -### Error Logging +### Error logging Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown. - **Required Methods**: `log`, `warn`, `error` @@ -1305,15 +1305,13 @@ Using the `logger` option when initiallizing Ajv will allow you to define custom var otherLogger = new OtherLogger(); var ajv = new Ajv({ logger: { - log: function log(_log) { - return console.log(_log); + log: console.log.bind(console), + warn: function warn() { + otherLogger.logWarn.apply(otherLogger, arguments); }, - warn: function warn(_warn) { - return otherLogger.logWarn(_warn); - }, - error: function error(_error) { - otherLogger.logError(_error); - return console.error(_error); + error: function error() { + otherLogger.logError.apply(otherLogger, arguments); + console.error.apply(console, arguments); } } }); From 03d0012f0cf35a834933de07d79522fe7ec9e90a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 22 Feb 2020 13:40:26 +0000 Subject: [PATCH 063/127] 6.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5cfec97d2..419583ece 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.11.0", + "version": "6.12.0", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From b15a73cdc1c1b0bd1859f3f26193c22101f51fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quin=CC=83o=CC=81nez=2C=20Carlo=20J?= Date: Thu, 23 Jan 2020 16:15:53 -0800 Subject: [PATCH 064/127] Add to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d645c3f70..544b25aa3 100644 --- a/README.md +++ b/README.md @@ -1309,7 +1309,7 @@ If you have published a useful plugin please submit a PR to add it to the next s - [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.) - [ajv-merge-patch](https://github.com/epoberezkin/ajv-merge-patch) - plugin with keywords $merge and $patch - [ajv-pack](https://github.com/epoberezkin/ajv-pack) - produces a compact module exporting validation functions - +- [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't already included in ajv (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`). ## Some packages using Ajv From 0775bc1a6c5c313138373a2047b1b8772128873f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 22 Mar 2020 11:38:03 +0000 Subject: [PATCH 065/127] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index c77c8e485..5dcdc3e50 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ +github: epoberezkin tidelift: "npm/ajv" -open_collective: "ajv" From 9f5752c1ff4b3cb5f078c4bccbc464a97828397f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Apr 2020 22:54:06 +0100 Subject: [PATCH 066/127] docs: sponsor --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e7450b4a..788298b22 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,49 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) [![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master) -[![Greenkeeper badge](https://badges.greenkeeper.io/epoberezkin/ajv.svg)](https://greenkeeper.io/) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) +[![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) + +## Please sponsor Ajv development + +Dear Ajv users! ❤️ + +I ask you to support the development of Ajv with donations. 🙏 + +Since 2015 Ajv has become widely used, thanks to your help and contributions: + +- **90** contributors 🏗 +- **5,000** dependent npm packages ⚙️ +- **7,000** github stars, from GitHub users [all over the world](https://www.google.com/maps/d/u/0/viewer?mid=1MGRV8ciFUGIbO1l0EKFWNJGYE7iSkDxP&ll=-3.81666561775622e-14%2C4.821737100000007&z=2) ⭐️ +- **5,000,000** dependent repositories on GitHub 🚀 +- **120,000,000** npm downloads per month! 💯 + +Your donations will fund futher development - small and large improvements, support of the next versions of JSON Schema specification, and, possibly, the code should be migrated to TypeScript to make it more maintainable. + +I will greatly appreciate anything you can help with to make it happen: + +- a **personal** donation - from $2 ☕️ +- your **company** donation - from $10 🍔 +- a **sponsorship** to get promoted on Ajv or related packages - from $50 💰 +- an **introduction** to a sponsor who would benefit from the promotion on Ajv page 🤝 + +| ‼️ Please make donations via [my GitHub sponsors page](https://github.com/sponsors/epoberezkin) - **GitHub pledged to DOUBLE them** ‼️ | +|---| + +#### Open Collective sponsors + + + + + + + + + + + + + ## Using version 6 From 081aeb0cd1b07e9a0f55b3226f1855062ba78cd9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 5 Apr 2020 13:39:40 +0100 Subject: [PATCH 067/127] docs: readme, open collective --- .github/FUNDING.yml | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5dcdc3e50..88fc551fa 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ github: epoberezkin tidelift: "npm/ajv" +open_collective: "ajv" diff --git a/README.md b/README.md index 788298b22..844dcb6cd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) -## Please sponsor Ajv development +## Please [sponsor Ajv](https://github.com/sponsors/epoberezkin) Dear Ajv users! ❤️ @@ -34,7 +34,7 @@ I will greatly appreciate anything you can help with to make it happen: - a **sponsorship** to get promoted on Ajv or related packages - from $50 💰 - an **introduction** to a sponsor who would benefit from the promotion on Ajv page 🤝 -| ‼️ Please make donations via [my GitHub sponsors page](https://github.com/sponsors/epoberezkin) - **GitHub pledged to DOUBLE them** ‼️ | +| Please [make donations via my GitHub sponsors page](https://github.com/sponsors/epoberezkin)
‼️ **GitHub will DOUBLE them** ‼️ | |---| #### Open Collective sponsors From 4e7786fcda9ed7f92ef52964db322a866c58d636 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2020 19:48:31 +0000 Subject: [PATCH 068/127] chore(package): update karma to version 5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 419583ece..8b7cded28 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "js-beautify": "^1.7.3", "jshint": "^2.10.2", "json-schema-test": "^2.0.0", - "karma": "^4.0.1", + "karma": "^5.0.0", "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.1.1", "karma-sauce-launcher": "^2.0.0", From f5c284cf924209a163039d319ed72b3cff5c1b78 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2020 16:31:37 +0000 Subject: [PATCH 069/127] chore(package): update karma-sauce-launcher to version 4.1.3 Closes #1174 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 419583ece..02458b9ad 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "karma": "^4.0.1", "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.1.1", - "karma-sauce-launcher": "^2.0.0", + "karma-sauce-launcher": "^4.1.3", "mocha": "^7.0.1", "nyc": "^15.0.0", "pre-commit": "^1.1.1", From 591b36e2378e9e4be81da1d59571888c2ea28f23 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2020 21:09:00 +0000 Subject: [PATCH 070/127] chore(package): update karma-mocha to version 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 419583ece..04e49a1da 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "json-schema-test": "^2.0.0", "karma": "^4.0.1", "karma-chrome-launcher": "^3.0.0", - "karma-mocha": "^1.1.1", + "karma-mocha": "^2.0.0", "karma-sauce-launcher": "^2.0.0", "mocha": "^7.0.1", "nyc": "^15.0.0", From bfced3b76a7ef7d3be0e4dac148c7c8aebe2dfb7 Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Sat, 18 Apr 2020 19:31:25 +1000 Subject: [PATCH 071/127] "hostname" format does not have full method Since v6.12.0 via #1143 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 844dcb6cd..e13fdec29 100644 --- a/README.md +++ b/README.md @@ -314,7 +314,7 @@ The following formats are implemented for string validation with "format" keywor __Please note__: JSON Schema draft-07 also defines formats `iri`, `iri-reference`, `idn-hostname` and `idn-email` for URLs, hostnames and emails with international characters. Ajv does not implement these formats. If you create Ajv plugin that implements them please make a PR to mention this plugin here. -There are two modes of format validation: `fast` and `full`. This mode affects formats `date`, `time`, `date-time`, `uri`, `uri-reference`, `email`, and `hostname`. See [Options](#options) for details. +There are two modes of format validation: `fast` and `full`. This mode affects formats `date`, `time`, `date-time`, `uri`, `uri-reference`, and `email`. See [Options](#options) for details. You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method. From 3e9f3759e3e0190de418e8253ee2ca7bf749a4a8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 18 Apr 2020 19:58:22 +0100 Subject: [PATCH 072/127] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d091a7625..e5b4b8fe4 100644 --- a/package.json +++ b/package.json @@ -85,8 +85,8 @@ "json-schema-test": "^2.0.0", "karma": "^5.0.0", "karma-chrome-launcher": "^3.0.0", - "karma-sauce-launcher": "^4.1.3", "karma-mocha": "^2.0.0", + "karma-sauce-launcher": "^4.1.3", "mocha": "^7.0.1", "nyc": "^15.0.0", "pre-commit": "^1.1.1", From 891f081862c4354eb5b837755b318cf9e6359244 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Apr 2020 20:22:38 +0100 Subject: [PATCH 073/127] update readme --- README.md | 32 +------------------------------- package.json | 2 +- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 1d984dae7..e13fdec29 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/07. [![Build Status](https://travis-ci.org/epoberezkin/ajv.svg?branch=master)](https://travis-ci.org/epoberezkin/ajv) -[![Financial Contributors on Open Collective](https://opencollective.com/ajv/all/badge.svg?label=financial+contributors)](https://opencollective.com/ajv) [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) +[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) [![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) @@ -1447,36 +1447,6 @@ __Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/r Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. -## Contributors - -### Code Contributors - -This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. - - -### Financial Contributors - -Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/ajv/contribute)] - -#### Individuals - - - -#### Organizations - -Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/ajv/contribute)] - - - - - - - - - - - - ## License [MIT](https://github.com/epoberezkin/ajv/blob/master/LICENSE) diff --git a/package.json b/package.json index 4fc7b222e..bca24d21b 100644 --- a/package.json +++ b/package.json @@ -101,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/ajv" } -} \ No newline at end of file +} From b511ae230f19519d5f16f55cd8959330327adb7a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 18 Apr 2020 20:28:21 +0100 Subject: [PATCH 074/127] 6.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bca24d21b..b75b84b34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.0", + "version": "6.12.1", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From 14bdb4b7576984c61be0b96c377efe7021f1564f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 19 Apr 2020 23:59:37 +0100 Subject: [PATCH 075/127] remove postinstall --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index b75b84b34..d2a3d2258 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,7 @@ "test-all": "npm run test-cov && if-node-version 10 npm run test-browser", "test": "npm run lint && npm run build && npm run test-all", "prepublish": "npm run build && npm run bundle", - "watch": "watch \"npm run build\" ./lib/dot", - "postinstall": "opencollective-postinstall || true" + "watch": "watch \"npm run build\" ./lib/dot" }, "nyc": { "exclude": [ @@ -66,7 +65,6 @@ "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", - "opencollective-postinstall": "^2.0.2", "uri-js": "^4.2.2" }, "devDependencies": { From 6a671057ea6aae690b5967ee26a0ddf8452c6297 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 19 Apr 2020 23:59:48 +0100 Subject: [PATCH 076/127] 6.12.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2a3d2258..024ddacd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.1", + "version": "6.12.2", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From b3ce7f348e73b3b9493cd7f39f02ebb373ae762d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 22 Apr 2020 18:25:59 +0100 Subject: [PATCH 077/127] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..410cda641 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at ajv.validator@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq From 1188d19e7931ae4a3b7988e4a1be278776d90d1d Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Sat, 25 Apr 2020 16:06:40 -0400 Subject: [PATCH 078/127] Pass schema object to processCode function --- README.md | 2 +- lib/ajv.d.ts | 2 +- lib/compile/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e13fdec29..434298610 100644 --- a/README.md +++ b/README.md @@ -1169,7 +1169,7 @@ Defaults: errorDataPath: 'object', // deprecated messages: true, sourceCode: false, - processCode: undefined, // function (str: string): string {} + processCode: undefined, // function (str: string, schema: object): string {} cache: new Cache, serialize: undefined } diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index cb600e168..d988c3a99 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -196,7 +196,7 @@ declare namespace ajv { errorDataPath?: string, messages?: boolean; sourceCode?: boolean; - processCode?: (code: string) => string; + processCode?: (code: string, schema: object) => string; cache?: object; logger?: CustomLogger | false; nullable?: boolean; diff --git a/lib/compile/index.js b/lib/compile/index.js index f4d3f0d58..97518c424 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -113,7 +113,7 @@ function compile(schema, root, localRefs, baseId) { + vars(defaults, defaultCode) + vars(customRules, customRuleCode) + sourceCode; - if (opts.processCode) sourceCode = opts.processCode(sourceCode); + if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema); // console.log('\n\n\n *** \n', JSON.stringify(sourceCode)); var validate; try { From 43b99974d9c02660d77d8961e712fe1fd69be790 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Mon, 27 Apr 2020 12:30:34 -0400 Subject: [PATCH 079/127] Update README about using js_beautify --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 434298610..c307eed04 100644 --- a/README.md +++ b/README.md @@ -1279,7 +1279,7 @@ Defaults: - _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/epoberezkin/ajv-i18n)). - _sourceCode_: add `sourceCode` property to validating function (for debugging; this code can be different from the result of toString call). - _processCode_: an optional function to process generated code before it is passed to Function constructor. It can be used to either beautify (the validating function is generated without line-breaks) or to transpile code. Starting from version 5.0.0 this option replaced options: - - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass `require('js-beautify').js_beautify`. + - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a fucntion calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`. - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/epoberezkin/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information. - _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)`, `del(key)` and `clear()`. - _serialize_: an optional function to serialize schema to cache key. Pass `false` to use schema itself as a key (e.g., if WeakMap used as a cache). By default [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used. From 8bc2067c61a84736271df599e35f54b76c2577d6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 27 Apr 2020 21:13:41 +0100 Subject: [PATCH 080/127] package.json funding --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 024ddacd4..0c085c672 100644 --- a/package.json +++ b/package.json @@ -98,5 +98,9 @@ "collective": { "type": "opencollective", "url": "https://opencollective.com/ajv" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" } } From b36e066055cc290f0525c43fcbe0935d571bf1b5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 27 Apr 2020 21:16:14 +0100 Subject: [PATCH 081/127] readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c307eed04..ebde8c500 100644 --- a/README.md +++ b/README.md @@ -1279,7 +1279,7 @@ Defaults: - _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/epoberezkin/ajv-i18n)). - _sourceCode_: add `sourceCode` property to validating function (for debugging; this code can be different from the result of toString call). - _processCode_: an optional function to process generated code before it is passed to Function constructor. It can be used to either beautify (the validating function is generated without line-breaks) or to transpile code. Starting from version 5.0.0 this option replaced options: - - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a fucntion calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`. + - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a function calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`. - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/epoberezkin/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information. - _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)`, `del(key)` and `clear()`. - _serialize_: an optional function to serialize schema to cache key. Pass `false` to use schema itself as a key (e.g., if WeakMap used as a cache). By default [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used. From 3a3b196cc8834e197f73a71cf4978b209179cccd Mon Sep 17 00:00:00 2001 From: Alexsey Date: Tue, 5 May 2020 11:56:24 +0300 Subject: [PATCH 082/127] docs: readme, update supported node versions https://github.com/epoberezkin/ajv/issues/1181 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebde8c500..5862db752 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Performance of different validators by [json-schema-benchmark](https://github.co - correct string lengths for strings with unicode pairs (can be turned off) - [formats](#formats) defined by JSON Schema draft-07 standard and custom formats (can be turned off) - [validates schemas against meta-schema](#api-validateschema) -- supports [browsers](#using-in-browser) and Node.js 0.10-8.x +- supports [browsers](#using-in-browser) and Node.js 0.10+ - [asynchronous loading](#asynchronous-schema-compilation) of referenced schemas during compilation - "All errors" validation mode with [option allErrors](#options) - [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages From eb4490cf473ac63fc166e4676e4d75200f5033ac Mon Sep 17 00:00:00 2001 From: Emily Marigold Klassen Date: Tue, 5 May 2020 22:17:18 -0700 Subject: [PATCH 083/127] Fix link to switch plugin in CUSTOM.md --- CUSTOM.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUSTOM.md b/CUSTOM.md index 4d3065e37..f1a43d5f8 100644 --- a/CUSTOM.md +++ b/CUSTOM.md @@ -294,7 +294,7 @@ The first parameter passed to inline keyword compilation function (and the 3rd p - _opts_ - Ajv instance option. You should not be changing them. - _formats_ - all formats available in Ajv instance, including the custom ones. - _compositeRule_ - boolean indicating that the current schema is inside the compound keyword where failing some rule doesn't mean validation failure (`anyOf`, `oneOf`, `not`, `if` in `switch`). This flag is used to determine whether you can return validation result immediately after any error in case the option `allErrors` is not `true. You only need to do it if you have many steps in your keywords and potentially can define multiple errors. -- _validate_ - the function you need to use to compile subschemas in your keywords (see the [implementation](https://github.com/epoberezkin/ajv/blob/master/lib/dot/v5/switch.jst) of `switch` keyword for example). +- _validate_ - the function you need to use to compile subschemas in your keywords (see the [implementation](https://github.com/epoberezkin/ajv-keywords/blob/master/keywords/dot/switch.jst) of `switch` keyword for example). - _util_ - [Ajv utilities](#ajv-utilities) you can use in your inline compilation functions. - _self_ - Ajv instance. From c9f27463998824b65df69610df60759da443dc5a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 6 May 2020 09:37:42 +0100 Subject: [PATCH 084/127] code of conduct link --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ebde8c500..6572f1a81 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,8 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Plugins](#plugins) - [Related packages](#related-packages) - [Some packages using Ajv](#some-packages-using-ajv) -- [Tests, Contributing, History, Support, License](#tests) +- [Tests, Contributing, Changes history](#tests) +- [Support, Code of conduct, License](#open-source-software-support) ## Performance @@ -1442,6 +1443,13 @@ __Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/r [Version 2.0.0](https://github.com/epoberezkin/ajv/releases/tag/2.0.0). +## Code of conduct + +Please review and follow the [Code of conduct](https://github.com/epoberezkin/ajv/blob/master/CODE_OF_CONDUCT.md). + +Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team. + + ## Open-source software support Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/npm-ajv?utm_source=npm-ajv&utm_medium=referral&utm_campaign=readme) - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers. From e828d45fdef996a6ab4b609e8b823ac3881339ae Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 6 May 2020 11:28:34 +0100 Subject: [PATCH 085/127] update readme --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6572f1a81..878ca35ef 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,18 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) -## Please [sponsor Ajv](https://github.com/sponsors/epoberezkin) -Dear Ajv users! ❤️ +## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin) -I ask you to support the development of Ajv with donations. 🙏 +I will get straight to the point - I need your support to ensure that the development of Ajv continues. + +I have developed Ajv for 5 years in my free time, but it is not sustainable. I'd appreciate if you consider supporting its further development with donations: +- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it) +- [Ajv Open Collective️](https://opencollective.com/ajv) + +There are many small and large improvements that are long due, including the support of the next versions of JSON Schema specification, improving website and documentation, and making Ajv more modular and maintainable to address its limitations - what Ajv needs to evolve is much more than what I can contribute in my free time. + +I would also really appreciate any advice you could give on how to raise funds for Ajv development - whether some suitable open-source fund I could apply to or some sponsor I should approach. Since 2015 Ajv has become widely used, thanks to your help and contributions: @@ -25,17 +32,10 @@ Since 2015 Ajv has become widely used, thanks to your help and contributions: - **5,000,000** dependent repositories on GitHub 🚀 - **120,000,000** npm downloads per month! 💯 -Your donations will fund futher development - small and large improvements, support of the next versions of JSON Schema specification, and, possibly, the code should be migrated to TypeScript to make it more maintainable. - -I will greatly appreciate anything you can help with to make it happen: +I believe it would benefit all Ajv users to help put together the fund that will be used for its further development - it would allow to bring some additional maintainers to the project. -- a **personal** donation - from $2 ☕️ -- your **company** donation - from $10 🍔 -- a **sponsorship** to get promoted on Ajv or related packages - from $50 💰 -- an **introduction** to a sponsor who would benefit from the promotion on Ajv page 🤝 +Thank you -| Please [make donations via my GitHub sponsors page](https://github.com/sponsors/epoberezkin)
‼️ **GitHub will DOUBLE them** ‼️ | -|---| #### Open Collective sponsors From ce8209a75f967e8aa718ed7fa3b77c15d27ca762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Fri, 8 May 2020 22:07:43 +0200 Subject: [PATCH 086/127] Add tests for Node 14.x --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f25c1418..b053cda9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,11 @@ before_script: - git submodule update --init - npm install -g codeclimate-test-reporter node_js: - - "8" - - "10" - - "11" - - "12" + - 8 + - 10 + - 11 + - 12 + - 14 after_script: - codeclimate-test-reporter < coverage/lcov.info - coveralls < coverage/lcov.info From 3ff84f37ee5af32093df7a654b76a3a9c331af40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 9 May 2020 17:33:18 +0200 Subject: [PATCH 087/127] Remove Node 11 from tests --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b053cda9c..11a0afa18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ before_script: node_js: - 8 - 10 - - 11 - 12 - 14 after_script: From 66e8a356fbd5124d065caaaddea2e8122ebed5fd Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 9 May 2020 17:47:02 +0100 Subject: [PATCH 088/127] fix logo url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 878ca35ef..12b271cb9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Ajv logo +Ajv logo # Ajv: Another JSON Schema Validator From b392b01764f44a42bcc8500281fab41221291f62 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 11 May 2020 17:26:23 +0100 Subject: [PATCH 089/127] change links to ajv-validator org --- .github/ISSUE_TEMPLATE.md | 12 +- .github/ISSUE_TEMPLATE/bug-or-error-report.md | 8 +- .github/ISSUE_TEMPLATE/change.md | 4 +- .github/ISSUE_TEMPLATE/compatibility.md | 4 +- .github/ISSUE_TEMPLATE/installation.md | 4 +- .github/ISSUE_TEMPLATE/typescript.md | 4 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/config.yml | 4 +- COERCION.md | 2 +- CONTRIBUTING.md | 18 +-- CUSTOM.md | 14 +-- FAQ.md | 14 +-- KEYWORDS.md | 6 +- README.md | 116 +++++++++--------- bower.json | 2 +- lib/compile/equal.js | 2 +- lib/data.js | 2 +- lib/definition_schema.js | 2 +- lib/keyword.js | 2 +- lib/refs/data.json | 2 +- lib/refs/json-schema-secure.json | 2 +- package.json | 6 +- scripts/publish-built-version | 2 +- scripts/travis-gh-pages | 2 +- spec/security/array.json | 6 +- spec/security/object.json | 2 +- spec/security/string.json | 4 +- 27 files changed, 124 insertions(+), 124 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index ef1c8f934..558501036 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,12 +1,12 @@ @@ -16,7 +16,7 @@ This template is for bug or error reports. For other issues please use: **Ajv options object** - + ```javascript @@ -49,7 +49,7 @@ This template is for bug or error reports. For other issues please use: **What version of Ajv are you using? Does the issue happen if you use the latest version?** @@ -21,7 +21,7 @@ For other issues please see https://github.com/epoberezkin/ajv/blob/master/CONTR **Ajv options object** - + ```javascript @@ -54,7 +54,7 @@ For other issues please see https://github.com/epoberezkin/ajv/blob/master/CONTR **What version of Ajv you are you using?** diff --git a/.github/ISSUE_TEMPLATE/compatibility.md b/.github/ISSUE_TEMPLATE/compatibility.md index 02b649dc7..79aa63999 100644 --- a/.github/ISSUE_TEMPLATE/compatibility.md +++ b/.github/ISSUE_TEMPLATE/compatibility.md @@ -8,11 +8,11 @@ assignees: '' --- **The version of Ajv you are using** diff --git a/.github/ISSUE_TEMPLATE/installation.md b/.github/ISSUE_TEMPLATE/installation.md index 6ebbddd0e..1786e9f2f 100644 --- a/.github/ISSUE_TEMPLATE/installation.md +++ b/.github/ISSUE_TEMPLATE/installation.md @@ -8,11 +8,11 @@ assignees: '' --- **What version of Ajv are you using? Does the issue happen if you use the latest version?** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d7feecdbd..7abf655f1 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,7 @@ Thank you for submitting a pull request to Ajv. Before continuing, please read the guidelines: -https://github.com/epoberezkin/ajv/blob/master/CONTRIBUTING.md#pull-requests +https://github.com/ajv-validator/ajv/blob/master/CONTRIBUTING.md#pull-requests If the pull request contains code please make sure there is an issue that we agreed to resolve (if it is a documentation improvement there is no need for an issue). diff --git a/.github/config.yml b/.github/config.yml index ce9efb997..1f6c1054f 100644 --- a/.github/config.yml +++ b/.github/config.yml @@ -25,8 +25,8 @@ githubLabels: - [Tutorial by Space Telescope Science Institute](http://json-schema.org/understanding-json-schema/) - - [validation keywords](https://github.com/epoberezkin/ajv#validation-keywords) (in Ajv docs) + - [validation keywords](https://github.com/ajv-validator/ajv#validation-keywords) (in Ajv docs) - - [combining schemas](https://github.com/epoberezkin/ajv#ref) (in Ajv docs) + - [combining schemas](https://github.com/ajv-validator/ajv#ref) (in Ajv docs) - [Tutorial by @epoberezkin](https://code.tutsplus.com/tutorials/validating-data-with-json-schema-part-1--cms-25343) diff --git a/COERCION.md b/COERCION.md index f310c2d67..6a0a41a68 100644 --- a/COERCION.md +++ b/COERCION.md @@ -1,6 +1,6 @@ # Ajv type coercion rules -To enable type coercion pass option `coerceTypes` to Ajv with `true` or `array` (it is `false` by default). See [example](https://github.com/epoberezkin/ajv#coercing-data-types). +To enable type coercion pass option `coerceTypes` to Ajv with `true` or `array` (it is `false` by default). See [example](https://github.com/ajv-validator/ajv#coercing-data-types). The coercion rules are different from JavaScript: - to validate user input as expected diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26f4bf029..4f2f8aaed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ Ajv has a lot of features and maintaining documentation takes time. I appreciate ## Issues -Before submitting the issue please search the existing issues and also review [Frequently Asked Questions](https://github.com/epoberezkin/ajv/blob/master/FAQ.md). +Before submitting the issue please search the existing issues and also review [Frequently Asked Questions](https://github.com/ajv-validator/ajv/blob/master/FAQ.md). I would really appreciate the time you spend providing all the information and reducing both your schema and data to the smallest possible size when they still have the issue. Simplifying the issue also makes it more valuable for other users (in cases it turns out to be an incorrect usage rather than a bug). @@ -34,7 +34,7 @@ I would really appreciate the time you spend providing all the information and r Please make sure to include the following information in the issue: 1. What version of Ajv are you using? Does the issue happen if you use the latest version? -2. Ajv options object (see https://github.com/epoberezkin/ajv#options). +2. Ajv options object (see https://github.com/ajv-validator/ajv#options). 3. JSON Schema and the data you are validating (please make it as small as possible to reproduce the issue). 4. Your code (please use `options`, `schema` and `data` as variables). 5. Validation result, data AFTER validation, error messages. @@ -42,7 +42,7 @@ Please make sure to include the following information in the issue: Please include the link to the working code sample at Runkit.com (please clone https://runkit.com/esp/ajv-issue) - it will speed up investigation and fixing. -[Create bug report](https://github.com/epoberezkin/ajv/issues/new?template=bug-or-error-report.md). +[Create bug report](https://github.com/ajv-validator/ajv/issues/new?template=bug-or-error-report.md). #### Security vulnerabilities @@ -56,7 +56,7 @@ Please do NOT report security vulnerabilities via GitHub issues. #### Change proposals -[Create a proposal](https://github.com/epoberezkin/ajv/issues/new?template=change.md) for a new feature, option or some other improvement. +[Create a proposal](https://github.com/ajv-validator/ajv/issues/new?template=change.md) for a new feature, option or some other improvement. Please include this information: @@ -76,7 +76,7 @@ Please include as much details as possible. #### Browser and compatibility issues -[Create an issue](https://github.com/epoberezkin/ajv/issues/new?template=compatibility.md) to report a compatibility problem that only happens in a particular environment (when your code works correctly in node.js v8+ in linux systems but fails in some other environment). +[Create an issue](https://github.com/ajv-validator/ajv/issues/new?template=compatibility.md) to report a compatibility problem that only happens in a particular environment (when your code works correctly in node.js v8+ in linux systems but fails in some other environment). Please include this information: @@ -90,7 +90,7 @@ Please include this information: #### Installation and dependency issues -[Create an issue](https://github.com/epoberezkin/ajv/issues/new?template=installation.md) to report problems that happen during Ajv installation or when Ajv is missing some dependency. +[Create an issue](https://github.com/ajv-validator/ajv/issues/new?template=installation.md) to report problems that happen during Ajv installation or when Ajv is missing some dependency. Before submitting the issue, please try the following: - use the latest stable Node.js and `npm` @@ -143,9 +143,9 @@ npm run test-fast git commit -nm 'type: message' ``` -All validation functions are generated using doT templates in [dot](https://github.com/epoberezkin/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency. +All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency. -`npm run build` - compiles templates to [dotjs](https://github.com/epoberezkin/ajv/tree/master/lib/dotjs) folder. +`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder. `npm run watch` - automatically compiles templates when files in dot folder change @@ -154,7 +154,7 @@ All validation functions are generated using doT templates in [dot](https://gith To make accepting your changes faster please follow these steps: -1. Submit an [issue with the bug](https://github.com/epoberezkin/ajv/issues/new) or with the proposed change (unless the contribution is to fix the documentation typos and mistakes). +1. Submit an [issue with the bug](https://github.com/ajv-validator/ajv/issues/new) or with the proposed change (unless the contribution is to fix the documentation typos and mistakes). 2. Please describe the proposed api and implementation plan (unless the issue is a relatively simple bug and fixing it doesn't change any api). 3. Once agreed, please write as little code as possible to achieve the desired result. 4. Please avoid unnecessary changes, refactoring or changing coding styles as part of your change (unless the change was proposed as refactoring). diff --git a/CUSTOM.md b/CUSTOM.md index f1a43d5f8..68cac5ab3 100644 --- a/CUSTOM.md +++ b/CUSTOM.md @@ -34,7 +34,7 @@ This way to define keywords is useful for: - testing your keywords before converting them to compiled/inlined keywords - defining keywords that do not depend on the schema value (e.g., when the value is always `true`). In this case you can add option `schema: false` to the keyword definition and the schemas won't be passed to the validation function, it will only receive the same 4 parameters as compiled validation function (see the next section). - defining keywords where the schema is a value used in some expression. -- defining keywords that support [$data reference](https://github.com/epoberezkin/ajv#data-reference) - in this case validation function is required, either as the only option or in addition to compile, macro or inline function (see below). +- defining keywords that support [$data reference](https://github.com/ajv-validator/ajv#data-reference) - in this case validation function is required, either as the only option or in addition to compile, macro or inline function (see below). __Please note__: In cases when validation flow is different depending on the schema and you have to use `if`s, this way to define keywords will have worse performance than compiled keyword returning different validation functions depending on the schema. @@ -197,7 +197,7 @@ console.log(validate([3,4,5])); // true, number 5 matches schema inside "contain `contains` keyword is already available in Ajv with option `v5: true`. -See the example of defining recursive macro keyword `deepProperties` in the [test](https://github.com/epoberezkin/ajv/blob/master/spec/custom.spec.js#L151). +See the example of defining recursive macro keyword `deepProperties` in the [test](https://github.com/ajv-validator/ajv/blob/master/spec/custom.spec.js#L151). ### Define keyword with "inline" compilation function @@ -294,7 +294,7 @@ The first parameter passed to inline keyword compilation function (and the 3rd p - _opts_ - Ajv instance option. You should not be changing them. - _formats_ - all formats available in Ajv instance, including the custom ones. - _compositeRule_ - boolean indicating that the current schema is inside the compound keyword where failing some rule doesn't mean validation failure (`anyOf`, `oneOf`, `not`, `if` in `switch`). This flag is used to determine whether you can return validation result immediately after any error in case the option `allErrors` is not `true. You only need to do it if you have many steps in your keywords and potentially can define multiple errors. -- _validate_ - the function you need to use to compile subschemas in your keywords (see the [implementation](https://github.com/epoberezkin/ajv-keywords/blob/master/keywords/dot/switch.jst) of `switch` keyword for example). +- _validate_ - the function you need to use to compile subschemas in your keywords (see the [implementation](https://github.com/ajv-validator/ajv-keywords/blob/master/keywords/dot/switch.jst) of `switch` keyword for example). - _util_ - [Ajv utilities](#ajv-utilities) you can use in your inline compilation functions. - _self_ - Ajv instance. @@ -311,8 +311,8 @@ There is a number of variables and expressions you can use in the generated (val - `'validate.schema' + it.schemaPath` - current level schema available at validation time (the same schema at compile time is `it.schema`). - `'validate.schema' + it.schemaPath + '.' + keyword` - the value of your custom keyword at validation-time. Keyword is passed as the second parameter to the inline compilation function to allow using the same function to compile multiple keywords. - `'valid' + it.level` - the variable that you have to declare and to assign the validation result to if your keyword returns statements rather than expression (`statements: true`). -- `'errors'` - the number of encountered errors. See [Reporting errors in custom keywords](https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md#reporting-errors-in-custom-keywords). -- `'vErrors'` - the array with errors collected so far. See [Reporting errors in custom keywords](https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md#reporting-errors-in-custom-keywords). +- `'errors'` - the number of encountered errors. See [Reporting errors in custom keywords](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md#reporting-errors-in-custom-keywords). +- `'vErrors'` - the array with errors collected so far. See [Reporting errors in custom keywords](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md#reporting-errors-in-custom-keywords). ## Ajv utilities @@ -410,7 +410,7 @@ All custom keywords but macro keywords can optionally create custom error messag Synchronous validating and compiled keywords should define errors by assigning them to `.errors` property of the validation function. Asynchronous keywords can return promise that rejects with `new Ajv.ValidationError(errors)`, where `errors` is an array of custom validation errors (if you don't want to define custom errors in asynchronous keyword, its validation function can return the promise that resolves with `false`). -Inline custom keyword should increase error counter `errors` and add error to `vErrors` array (it can be null). This can be done for both synchronous and asynchronous keywords. See [example range keyword](https://github.com/epoberezkin/ajv/blob/master/spec/custom_rules/range_with_errors.jst). +Inline custom keyword should increase error counter `errors` and add error to `vErrors` array (it can be null). This can be done for both synchronous and asynchronous keywords. See [example range keyword](https://github.com/ajv-validator/ajv/blob/master/spec/custom_rules/range_with_errors.jst). When inline keyword performs validation Ajv checks whether it created errors by comparing errors count before and after validation. To skip this check add option `errors` (can be `"full"`, `true` or `false`) to keyword definition: @@ -429,7 +429,7 @@ Each error object should at least have properties `keyword`, `message` and `para Inlined keywords can optionally define `dataPath` and `schemaPath` properties in error objects, that will be assigned by Ajv unless `errors` option of the keyword is `"full"`. -If custom keyword doesn't create errors, the default error will be created in case the keyword fails validation (see [Validation errors](https://github.com/epoberezkin/ajv#validation-errors)). +If custom keyword doesn't create errors, the default error will be created in case the keyword fails validation (see [Validation errors](https://github.com/ajv-validator/ajv#validation-errors)). ## Short-circuit validation diff --git a/FAQ.md b/FAQ.md index 36ac967cd..f010a51c8 100644 --- a/FAQ.md +++ b/FAQ.md @@ -9,7 +9,7 @@ The purpose of this document is to help find answers quicker. I am happy to cont Ajv implements JSON schema specification. Before submitting the issue about the behaviour of any validation keywords please review them in: - [JSON Schema specification](https://tools.ietf.org/html/draft-handrews-json-schema-validation-00) (draft-07) -- [Validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md) in Ajv documentation +- [Validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md) in Ajv documentation - [JSON Schema tutorial](https://spacetelescope.github.io/understanding-json-schema/) (for draft-04) @@ -20,13 +20,13 @@ Ajv implements JSON schema specification. Before submitting the issue about the ##### Why Ajv validates only the first item of the array? -"items" keyword support [two syntaxes](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#items) - 1) when the schema applies to all items; 2) when there is a different schema for each item in the beginning of the array. This problem means you are using the second syntax. +"items" keyword support [two syntaxes](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#items) - 1) when the schema applies to all items; 2) when there is a different schema for each item in the beginning of the array. This problem means you are using the second syntax. ## Ajv API for returning validation errors -See [#65](https://github.com/epoberezkin/ajv/issues/65), [#212](https://github.com/epoberezkin/ajv/issues/212), [#236](https://github.com/epoberezkin/ajv/issues/236), [#242](https://github.com/epoberezkin/ajv/issues/242), [#256](https://github.com/epoberezkin/ajv/issues/256). +See [#65](https://github.com/ajv-validator/ajv/issues/65), [#212](https://github.com/ajv-validator/ajv/issues/212), [#236](https://github.com/ajv-validator/ajv/issues/236), [#242](https://github.com/ajv-validator/ajv/issues/242), [#256](https://github.com/ajv-validator/ajv/issues/256). ##### Why Ajv assigns errors as a property of validation function (or instance) instead of returning an object with validation results and errors? @@ -56,7 +56,7 @@ Since the property name is already in the params object, in an application you c ## Additional properties inside compound keywords anyOf, oneOf, etc. -See [#127](https://github.com/epoberezkin/ajv/issues/127), [#129](https://github.com/epoberezkin/ajv/issues/129), [#134](https://github.com/epoberezkin/ajv/issues/134), [#140](https://github.com/epoberezkin/ajv/issues/140), [#193](https://github.com/epoberezkin/ajv/issues/193), [#205](https://github.com/epoberezkin/ajv/issues/205), [#238](https://github.com/epoberezkin/ajv/issues/238), [#264](https://github.com/epoberezkin/ajv/issues/264). +See [#127](https://github.com/ajv-validator/ajv/issues/127), [#129](https://github.com/ajv-validator/ajv/issues/129), [#134](https://github.com/ajv-validator/ajv/issues/134), [#140](https://github.com/ajv-validator/ajv/issues/140), [#193](https://github.com/ajv-validator/ajv/issues/193), [#205](https://github.com/ajv-validator/ajv/issues/205), [#238](https://github.com/ajv-validator/ajv/issues/238), [#264](https://github.com/ajv-validator/ajv/issues/264). ##### Why the keyword `additionalProperties: false` fails validation when some properties are "declared" inside a subschema in `anyOf`/etc.? @@ -85,13 +85,13 @@ There are several ways to implement the described logic that would allow two pro This problem is related to the problem explained above - properties treated as additional in the sense of `additionalProperties` keyword, based on `properties`/`patternProperties` keyword in the same schema object. -See the exemple in [Filtering Data](https://github.com/epoberezkin/ajv#filtering-data) section of readme. +See the exemple in [Filtering Data](https://github.com/ajv-validator/ajv#filtering-data) section of readme. ## Generating schemas with resolved references ($ref) -See [#22](https://github.com/epoberezkin/ajv/issues/22), [#125](https://github.com/epoberezkin/ajv/issues/125), [#146](https://github.com/epoberezkin/ajv/issues/146), [#228](https://github.com/epoberezkin/ajv/issues/228), [#336](https://github.com/epoberezkin/ajv/issues/336), [#454](https://github.com/epoberezkin/ajv/issues/454). +See [#22](https://github.com/ajv-validator/ajv/issues/22), [#125](https://github.com/ajv-validator/ajv/issues/125), [#146](https://github.com/ajv-validator/ajv/issues/146), [#228](https://github.com/ajv-validator/ajv/issues/228), [#336](https://github.com/ajv-validator/ajv/issues/336), [#454](https://github.com/ajv-validator/ajv/issues/454). ##### Why Ajv does not replace references ($ref) with the actual referenced schemas as some validators do? @@ -108,4 +108,4 @@ There were many conversations about the meaning of `$ref` in [JSON Schema GitHub There are two possible approaches: 1. Traverse schema (e.g. with json-schema-traverse) and replace every `$ref` with the referenced schema. -2. Use a specially constructed JSON Schema with a [custom keyword](https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md) to traverse and modify your schema. +2. Use a specially constructed JSON Schema with a [custom keyword](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md) to traverse and modify your schema. diff --git a/KEYWORDS.md b/KEYWORDS.md index 32740dc41..6601a9a1b 100644 --- a/KEYWORDS.md +++ b/KEYWORDS.md @@ -202,7 +202,7 @@ _invalid_: `"abc"` ### `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` (proposed) -Defined in [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package. +Defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package. The value of keyword `formatMaximum` (`formatMinimum`) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword. @@ -618,7 +618,7 @@ _invalid_: `{"foo": "any value"}` ### `patternRequired` (proposed) -Defined in [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package. +Defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package. The value of this keyword should be an array of strings, each string being a regular expression. For data object to be valid each regular expression in this array should match at least one property name in the data object. @@ -670,7 +670,7 @@ _valid_: `"foo"` _invalid_: any other value -The same can be achieved with `enum` keyword using the array with one item. But `const` keyword is more than just a syntax sugar for `enum`. In combination with the [$data reference](https://github.com/epoberezkin/ajv#data-reference) it allows to define equality relations between different parts of the data. This cannot be achieved with `enum` keyword even with `$data` reference because `$data` cannot be used in place of one item - it can only be used in place of the whole array in `enum` keyword. +The same can be achieved with `enum` keyword using the array with one item. But `const` keyword is more than just a syntax sugar for `enum`. In combination with the [$data reference](https://github.com/ajv-validator/ajv#data-reference) it allows to define equality relations between different parts of the data. This cannot be achieved with `enum` keyword even with `$data` reference because `$data` cannot be used in place of one item - it can only be used in place of the whole array in `enum` keyword. __Example__ diff --git a/README.md b/README.md index 12b271cb9..b0f7bda07 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Thank you [JSON Schema draft-07](http://json-schema.org/latest/json-schema-validation.html) is published. -[Ajv version 6.0.0](https://github.com/epoberezkin/ajv/releases/tag/v6.0.0) that supports draft-07 is released. It may require either migrating your schemas or updating your code (to continue using draft-04 and v5 schemas, draft-06 schemas will be supported without changes). +[Ajv version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0) that supports draft-07 is released. It may require either migrating your schemas or updating your code (to continue using draft-04 and v5 schemas, draft-06 schemas will be supported without changes). __Please note__: To use Ajv with draft-06 schemas you need to explicitly add the meta-schema to the validator instance: @@ -80,7 +80,7 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Performance](#performance) - [Features](#features) - [Getting started](#getting-started) -- [Frequently Asked Questions](https://github.com/epoberezkin/ajv/blob/master/FAQ.md) +- [Frequently Asked Questions](https://github.com/ajv-validator/ajv/blob/master/FAQ.md) - [Using in browser](#using-in-browser) - [Command line interface](#command-line-interface) - Validation @@ -134,7 +134,7 @@ Performance of different validators by [json-schema-benchmark](https://github.co ## Features - Ajv implements full JSON Schema [draft-06/07](http://json-schema.org/) and draft-04 standards: - - all validation keywords (see [JSON Schema validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md)) + - all validation keywords (see [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md)) - full support of remote refs (remote schemas have to be added with `addSchema` or compiled to be available) - support of circular references between schemas - correct string lengths for strings with unicode pairs (can be turned off) @@ -144,14 +144,14 @@ Performance of different validators by [json-schema-benchmark](https://github.co - [asynchronous loading](#asynchronous-schema-compilation) of referenced schemas during compilation - "All errors" validation mode with [option allErrors](#options) - [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages -- i18n error messages support with [ajv-i18n](https://github.com/epoberezkin/ajv-i18n) package +- i18n error messages support with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package - [filtering data](#filtering-data) from additional properties - [assigning defaults](#assigning-defaults) to missing properties and items - [coercing data](#coercing-data-types) to the types specified in `type` keywords - [custom keywords](#defining-custom-keywords) - draft-06/07 keywords `const`, `contains`, `propertyNames` and `if/then/else` - draft-06 boolean schemas (`true`/`false` as a schema to always pass/fail). -- keywords `switch`, `patternRequired`, `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) with [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package +- keywords `switch`, `patternRequired`, `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) with [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package - [$data reference](#data-reference) to use values from the validated data as values for the schema keywords - [asynchronous validation](#asynchronous-validation) of custom formats and keywords @@ -235,15 +235,15 @@ Ajv is tested with these browsers: [![Sauce Test Status](https://saucelabs.com/browser-matrix/epoberezkin.svg)](https://saucelabs.com/u/epoberezkin) -__Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/epoberezkin/ajv/issues/234)). +__Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)). ## Command line interface -CLI is available as a separate npm package [ajv-cli](https://github.com/jessedc/ajv-cli). It supports: +CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports: - compiling JSON Schemas to test their validity -- BETA: generating standalone module exporting a validation function to be used without Ajv (using [ajv-pack](https://github.com/epoberezkin/ajv-pack)) +- BETA: generating standalone module exporting a validation function to be used without Ajv (using [ajv-pack](https://github.com/ajv-validator/ajv-pack)) - migrate schemas to draft-07 (using [json-schema-migrate](https://github.com/epoberezkin/json-schema-migrate)) - validating data file(s) against JSON Schema - testing expected validity of data against JSON Schema @@ -258,20 +258,20 @@ CLI is available as a separate npm package [ajv-cli](https://github.com/jessedc/ Ajv supports all validation keywords from draft-07 of JSON Schema standard: -- [type](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#type) -- [for numbers](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-numbers) - maximum, minimum, exclusiveMaximum, exclusiveMinimum, multipleOf -- [for strings](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-strings) - maxLength, minLength, pattern, format -- [for arrays](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-arrays) - maxItems, minItems, uniqueItems, items, additionalItems, [contains](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#contains) -- [for objects](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-objects) - maxProperties, minProperties, required, properties, patternProperties, additionalProperties, dependencies, [propertyNames](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#propertynames) -- [for all types](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#keywords-for-all-types) - enum, [const](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#const) -- [compound keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#compound-keywords) - not, oneOf, anyOf, allOf, [if/then/else](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#ifthenelse) +- [type](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#type) +- [for numbers](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-numbers) - maximum, minimum, exclusiveMaximum, exclusiveMinimum, multipleOf +- [for strings](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-strings) - maxLength, minLength, pattern, format +- [for arrays](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-arrays) - maxItems, minItems, uniqueItems, items, additionalItems, [contains](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#contains) +- [for objects](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-objects) - maxProperties, minProperties, required, properties, patternProperties, additionalProperties, dependencies, [propertyNames](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#propertynames) +- [for all types](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#keywords-for-all-types) - enum, [const](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#const) +- [compound keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#compound-keywords) - not, oneOf, anyOf, allOf, [if/then/else](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#ifthenelse) -With [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package Ajv also supports validation keywords from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) for JSON Schema standard: +With [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package Ajv also supports validation keywords from [JSON Schema extension proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) for JSON Schema standard: -- [patternRequired](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#patternrequired-proposed) - like `required` but with patterns that some property should match. -- [formatMaximum, formatMinimum, formatExclusiveMaximum, formatExclusiveMinimum](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#formatmaximum--formatminimum-and-exclusiveformatmaximum--exclusiveformatminimum-proposed) - setting limits for date, time, etc. +- [patternRequired](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#patternrequired-proposed) - like `required` but with patterns that some property should match. +- [formatMaximum, formatMinimum, formatExclusiveMaximum, formatExclusiveMinimum](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md#formatmaximum--formatminimum-and-exclusiveformatmaximum--exclusiveformatminimum-proposed) - setting limits for date, time, etc. -See [JSON Schema validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md) for more details. +See [JSON Schema validation keywords](https://github.com/ajv-validator/ajv/blob/master/KEYWORDS.md) for more details. ## Annotation keywords @@ -321,7 +321,7 @@ You can add additional formats and replace any of the formats above using [addFo The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can whitelist specific format(s) to be ignored. See [Options](#options) for details. -You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/epoberezkin/ajv/blob/master/lib/compile/formats.js). +You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validatorv/ajv/blob/master/lib/compile/formats.js). ## Combining schemas with $ref @@ -430,7 +430,7 @@ var validData = { ## $merge and $patch keywords -With the package [ajv-merge-patch](https://github.com/epoberezkin/ajv-merge-patch) you can use the keywords `$merge` and `$patch` that allow extending JSON Schemas with patches using formats [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) and [JSON Patch (RFC 6902)](https://tools.ietf.org/html/rfc6902). +With the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) you can use the keywords `$merge` and `$patch` that allow extending JSON Schemas with patches using formats [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/html/rfc7396) and [JSON Patch (RFC 6902)](https://tools.ietf.org/html/rfc6902). To add keywords `$merge` and `$patch` to Ajv instance use this code: @@ -489,7 +489,7 @@ The schemas above are equivalent to this schema: The properties `source` and `with` in the keywords `$merge` and `$patch` can use absolute or relative `$ref` to point to other schemas previously added to the Ajv instance or to the fragments of the current schema. -See the package [ajv-merge-patch](https://github.com/epoberezkin/ajv-merge-patch) for more information. +See the package [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) for more information. ## Defining custom keywords @@ -537,9 +537,9 @@ console.log(validate(2)); // false console.log(validate(4)); // false ``` -Several custom keywords (typeof, instanceof, range and propertyNames) are defined in [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package - they can be used for your schemas and as a starting point for your own custom keywords. +Several custom keywords (typeof, instanceof, range and propertyNames) are defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package - they can be used for your schemas and as a starting point for your own custom keywords. -See [Defining custom keywords](https://github.com/epoberezkin/ajv/blob/master/CUSTOM.md) for more details. +See [Defining custom keywords](https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md) for more details. ## Asynchronous schema compilation @@ -638,7 +638,7 @@ validate({ userId: 1, postId: 19 }) ### Using transpilers with asynchronous validation functions. -[ajv-async](https://github.com/epoberezkin/ajv-async) uses [nodent](https://github.com/MatAtBread/nodent) to transpile async functions. To use another transpiler you should separately install it (or load its bundle in the browser). +[ajv-async](https://github.com/ajv-validator/ajv-async) uses [nodent](https://github.com/MatAtBread/nodent) to transpile async functions. To use another transpiler you should separately install it (or load its bundle in the browser). #### Using nodent @@ -682,7 +682,7 @@ Ajv treats JSON schemas as trusted as your application code. This security model If your schemas are received from untrusted sources (or generated from untrusted data) there are several scenarios you need to prevent: - compiling schemas can cause stack overflow (if they are too deep) -- compiling schemas can be slow (e.g. [#557](https://github.com/epoberezkin/ajv/issues/557)) +- compiling schemas can be slow (e.g. [#557](https://github.com/ajv-validator/ajv/issues/557)) - validating certain data can be slow It is difficult to predict all the scenarios, but at the very least it may help to limit the size of untrusted schemas (e.g. limit JSON string length) and also the maximum schema object depth (that can be high for relatively small JSON strings). You also may want to mitigate slow regular expressions in `pattern` and `patternProperties` keywords. @@ -692,7 +692,7 @@ Regardless the measures you take, using untrusted schemas increases security ris ##### Circular references in JavaScript objects -Ajv does not support schemas and validated data that have circular references in objects. See [issue #802](https://github.com/epoberezkin/ajv/issues/802). +Ajv does not support schemas and validated data that have circular references in objects. See [issue #802](https://github.com/ajv-validator/ajv/issues/802). An attempt to compile such schemas or validate such data would cause stack overflow (or will not complete in case of asynchronous validation). Depending on the parser you use, untrusted data can lead to circular references. @@ -707,7 +707,7 @@ Some keywords in JSON Schemas can lead to very slow validation for certain data. __Please note__: The suggestions above to prevent slow validation would only work if you do NOT use `allErrors: true` in production code (using it would continue validation after validation errors). -You can validate your JSON schemas against [this meta-schema](https://github.com/epoberezkin/ajv/blob/master/lib/refs/json-schema-secure.json) to check that these recommendations are followed: +You can validate your JSON schemas against [this meta-schema](https://github.com/ajv-validator/ajv/blob/master/lib/refs/json-schema-secure.json) to check that these recommendations are followed: ```javascript const isSchemaSecure = ajv.compile(require('ajv/lib/refs/json-schema-secure.json')); @@ -728,7 +728,7 @@ Certain regular expressions can lead to the exponential evaluation time even wit Please assess the regular expressions you use in the schemas on their vulnerability to this attack - see [safe-regex](https://github.com/substack/safe-regex), for example. -__Please note__: some formats that Ajv implements use [regular expressions](https://github.com/epoberezkin/ajv/blob/master/lib/compile/formats.js) that can be vulnerable to ReDoS attack, so if you use Ajv to validate data from untrusted sources __it is strongly recommended__ to consider the following: +__Please note__: some formats that Ajv implements use [regular expressions](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js) that can be vulnerable to ReDoS attack, so if you use Ajv to validate data from untrusted sources __it is strongly recommended__ to consider the following: - making assessment of "format" implementations in Ajv. - using `format: 'fast'` option that simplifies some of the regular expressions (although it does not guarantee that they are safe). @@ -808,7 +808,7 @@ The intention of the schema above is to allow objects with either the string pro With the option `removeAdditional: true` the validation will pass for the object `{ "foo": "abc"}` but will fail for the object `{"bar": 1}`. It happens because while the first subschema in `oneOf` is validated, the property `bar` is removed because it is an additional property according to the standard (because it is not included in `properties` keyword in the same schema). -While this behaviour is unexpected (issues [#129](https://github.com/epoberezkin/ajv/issues/129), [#134](https://github.com/epoberezkin/ajv/issues/134)), it is correct. To have the expected behaviour (both objects are allowed and additional properties are removed) the schema has to be refactored in this way: +While this behaviour is unexpected (issues [#129](https://github.com/ajv-validator/ajv/issues/129), [#134](https://github.com/ajv-validator/ajv/issues/134)), it is correct. To have the expected behaviour (both objects are allowed and additional properties are removed) the schema has to be refactored in this way: ```json { @@ -882,7 +882,7 @@ console.log(data); // [ 1, "foo" ] `default` keywords in other cases are ignored: - not in `properties` or `items` subschemas -- in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/epoberezkin/ajv/issues/42)) +- in schemas inside `anyOf`, `oneOf` and `not` (see [#42](https://github.com/ajv-validator/ajv/issues/42)) - in `if` subschema of `switch` keyword - in schemas generated by custom macro keywords @@ -940,7 +940,7 @@ console.log(data); // { "foo": [1], "bar": false } The coercion rules, as you can see from the example, are different from JavaScript both to validate user input as expected and to have the coercion reversible (to correctly validate cases where different types are defined in subschemas of "anyOf" and other compound keywords). -See [Coercion rules](https://github.com/epoberezkin/ajv/blob/master/COERCION.md) for details. +See [Coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md) for details. ## API @@ -1058,9 +1058,9 @@ Function should return validation result as `true` or `false`. If object is passed it should have properties `validate`, `compare` and `async`: - _validate_: a string, RegExp or a function as described above. -- _compare_: an optional comparison function that accepts two strings and compares them according to the format meaning. This function is used with keywords `formatMaximum`/`formatMinimum` (defined in [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) package). It should return `1` if the first value is bigger than the second value, `-1` if it is smaller and `0` if it is equal. +- _compare_: an optional comparison function that accepts two strings and compares them according to the format meaning. This function is used with keywords `formatMaximum`/`formatMinimum` (defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package). It should return `1` if the first value is bigger than the second value, `-1` if it is smaller and `0` if it is equal. - _async_: an optional `true` value if `validate` is an asynchronous function; in this case it should return a promise that resolves with a value `true` or `false`. -- _type_: an optional type of data that the format applies to. It can be `"string"` (default) or `"number"` (see https://github.com/epoberezkin/ajv/issues/291#issuecomment-259923858). If the type of data is different, the validation will pass. +- _type_: an optional type of data that the format applies to. It can be `"string"` (default) or `"number"` (see https://github.com/ajv-validator/ajv/issues/291#issuecomment-259923858). If the type of data is different, the validation will pass. Custom formats can be also added via `formats` option. @@ -1234,7 +1234,7 @@ Defaults: - `true` - insert defaults by value (object literal is used). - `"empty"` - in addition to missing or undefined, use defaults for properties and items that are equal to `null` or `""` (an empty string). - `"shared"` (deprecated) - insert defaults by reference. If the default is an object, it will be shared by all instances of validated data. If you modify the inserted default in the validated data, it will be modified in the schema as well. -- _coerceTypes_: change data type of data to match `type` keyword. See the example in [Coercing data types](#coercing-data-types) and [coercion rules](https://github.com/epoberezkin/ajv/blob/master/COERCION.md). Option values: +- _coerceTypes_: change data type of data to match `type` keyword. See the example in [Coercing data types](#coercing-data-types) and [coercion rules](https://github.com/ajv-validator/ajv/blob/master/COERCION.md). Option values: - `false` (default) - no type coercion. - `true` - coerce scalar data types. - `"array"` - in addition to coercions between scalar types, coerce scalar data to an array with one element and vice versa (as required by the schema). @@ -1254,7 +1254,7 @@ Defaults: ##### Asynchronous validation options -- _transpile_: Requires [ajv-async](https://github.com/epoberezkin/ajv-async) package. It determines whether Ajv transpiles compiled asynchronous validation function. Option values: +- _transpile_: Requires [ajv-async](https://github.com/ajv-validator/ajv-async) package. It determines whether Ajv transpiles compiled asynchronous validation function. Option values: - `undefined` (default) - transpile with [nodent](https://github.com/MatAtBread/nodent) if async functions are not supported. - `true` - always transpile with nodent. - `false` - do not transpile; if async functions are not supported an exception will be thrown. @@ -1275,13 +1275,13 @@ Defaults: - _passContext_: pass validation context to custom keyword functions. If this option is `true` and you pass some context to the compiled validation function with `validate.call(context, data)`, the `context` will be available as `this` in your custom keywords. By default `this` is Ajv instance. - _loopRequired_: by default `required` keyword is compiled into a single expression (or a sequence of statements in `allErrors` mode). In case of a very large number of properties in this keyword it may result in a very big validation function. Pass integer to set the number of properties above which `required` keyword will be validated in a loop - smaller validation function size but also worse performance. - _ownProperties_: by default Ajv iterates over all enumerable object properties; when this option is `true` only own enumerable object properties (i.e. found directly on the object rather than on its prototype) are iterated. Contributed by @mbroadst. -- _multipleOfPrecision_: by default `multipleOf` keyword is validated by comparing the result of division with parseInt() of that result. It works for dividers that are bigger than 1. For small dividers such as 0.01 the result of the division is usually not integer (even when it should be integer, see issue [#84](https://github.com/epoberezkin/ajv/issues/84)). If you need to use fractional dividers set this option to some positive integer N to have `multipleOf` validated using this formula: `Math.abs(Math.round(division) - division) < 1e-N` (it is slower but allows for float arithmetics deviations). +- _multipleOfPrecision_: by default `multipleOf` keyword is validated by comparing the result of division with parseInt() of that result. It works for dividers that are bigger than 1. For small dividers such as 0.01 the result of the division is usually not integer (even when it should be integer, see issue [#84](https://github.com/ajv-validator/ajv/issues/84)). If you need to use fractional dividers set this option to some positive integer N to have `multipleOf` validated using this formula: `Math.abs(Math.round(division) - division) < 1e-N` (it is slower but allows for float arithmetics deviations). - _errorDataPath_ (deprecated): set `dataPath` to point to 'object' (default) or to 'property' when validating keywords `required`, `additionalProperties` and `dependencies`. -- _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/epoberezkin/ajv-i18n)). +- _messages_: Include human-readable messages in errors. `true` by default. `false` can be passed when custom messages are used (e.g. with [ajv-i18n](https://github.com/ajv-validator/ajv-i18n)). - _sourceCode_: add `sourceCode` property to validating function (for debugging; this code can be different from the result of toString call). - _processCode_: an optional function to process generated code before it is passed to Function constructor. It can be used to either beautify (the validating function is generated without line-breaks) or to transpile code. Starting from version 5.0.0 this option replaced options: - `beautify` that formatted the generated function using [js-beautify](https://github.com/beautify-web/js-beautify). If you want to beautify the generated code pass a function calling `require('js-beautify').js_beautify` as `processCode: code => js_beautify(code)`. - - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/epoberezkin/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information. + - `transpile` that transpiled asynchronous validation function. You can still use `transpile` option with [ajv-async](https://github.com/ajv-validator/ajv-async) package. See [Asynchronous validation](#asynchronous-validation) for more information. - _cache_: an optional instance of cache to store compiled schemas using stable-stringified schema as a key. For example, set-associative cache [sacjs](https://github.com/epoberezkin/sacjs) can be used. If not passed then a simple hash is used which is good enough for the common use case (a limited number of statically defined schemas). Cache should have methods `put(key, value)`, `get(key)`, `del(key)` and `clear()`. - _serialize_: an optional function to serialize schema to cache key. Pass `false` to use schema itself as a key (e.g., if WeakMap used as a cache). By default [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used. @@ -1298,7 +1298,7 @@ Each error is an object with the following properties: - _keyword_: validation keyword. - _dataPath_: the path to the part of the data that was validated. By default `dataPath` uses JavaScript property access notation (e.g., `".prop[1].subProp"`). When the option `jsonPointers` is true (see [Options](#options)) `dataPath` will be set using JSON pointer standard (e.g., `"/prop/1/subProp"`). - _schemaPath_: the path (JSON-pointer as a URI fragment) to the schema of the keyword that failed validation. -- _params_: the object with the additional information about error that can be used to create custom error messages (e.g., using [ajv-i18n](https://github.com/epoberezkin/ajv-i18n) package). See below for parameters set by all keywords. +- _params_: the object with the additional information about error that can be used to create custom error messages (e.g., using [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) package). See below for parameters set by all keywords. - _message_: the standard error message (can be excluded with option `messages` set to false). - _schema_: the schema of the keyword (added with `verbose` option). - _parentSchema_: the schema containing the keyword (added with `verbose` option) @@ -1373,15 +1373,15 @@ If you have published a useful plugin please submit a PR to add it to the next s ## Related packages -- [ajv-async](https://github.com/epoberezkin/ajv-async) - plugin to configure async validation mode +- [ajv-async](https://github.com/ajv-validator/ajv-async) - plugin to configure async validation mode - [ajv-bsontype](https://github.com/BoLaMN/ajv-bsontype) - plugin to validate mongodb's bsonType formats - [ajv-cli](https://github.com/jessedc/ajv-cli) - command line interface -- [ajv-errors](https://github.com/epoberezkin/ajv-errors) - plugin for custom error messages -- [ajv-i18n](https://github.com/epoberezkin/ajv-i18n) - internationalised error messages -- [ajv-istanbul](https://github.com/epoberezkin/ajv-istanbul) - plugin to instrument generated validation code to measure test coverage of your schemas -- [ajv-keywords](https://github.com/epoberezkin/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.) -- [ajv-merge-patch](https://github.com/epoberezkin/ajv-merge-patch) - plugin with keywords $merge and $patch -- [ajv-pack](https://github.com/epoberezkin/ajv-pack) - produces a compact module exporting validation functions +- [ajv-errors](https://github.com/ajv-validator/ajv-errors) - plugin for custom error messages +- [ajv-i18n](https://github.com/ajv-validator/ajv-i18n) - internationalised error messages +- [ajv-istanbul](https://github.com/ajv-validator/ajv-istanbul) - plugin to instrument generated validation code to measure test coverage of your schemas +- [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) - plugin with custom validation keywords (select, typeof, etc.) +- [ajv-merge-patch](https://github.com/ajv-validator/ajv-merge-patch) - plugin with keywords $merge and $patch +- [ajv-pack](https://github.com/ajv-validator/ajv-pack) - produces a compact module exporting validation functions - [ajv-formats-draft2019](https://github.com/luzlab/ajv-formats-draft2019) - format validators for draft2019 that aren't already included in ajv (ie. `idn-hostname`, `idn-email`, `iri`, `iri-reference` and `duration`). ## Some packages using Ajv @@ -1419,33 +1419,33 @@ npm test ## Contributing -All validation functions are generated using doT templates in [dot](https://github.com/epoberezkin/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency. +All validation functions are generated using doT templates in [dot](https://github.com/ajv-validator/ajv/tree/master/lib/dot) folder. Templates are precompiled so doT is not a run-time dependency. -`npm run build` - compiles templates to [dotjs](https://github.com/epoberezkin/ajv/tree/master/lib/dotjs) folder. +`npm run build` - compiles templates to [dotjs](https://github.com/ajv-validator/ajv/tree/master/lib/dotjs) folder. `npm run watch` - automatically compiles templates when files in dot folder change -Please see [Contributing guidelines](https://github.com/epoberezkin/ajv/blob/master/CONTRIBUTING.md) +Please see [Contributing guidelines](https://github.com/ajv-validator/ajv/blob/master/CONTRIBUTING.md) ## Changes history -See https://github.com/epoberezkin/ajv/releases +See https://github.com/ajv-validator/ajv/releases -__Please note__: [Changes in version 6.0.0](https://github.com/epoberezkin/ajv/releases/tag/v6.0.0). +__Please note__: [Changes in version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0). -[Version 5.0.0](https://github.com/epoberezkin/ajv/releases/tag/5.0.0). +[Version 5.0.0](https://github.com/ajv-validator/ajv/releases/tag/5.0.0). -[Version 4.0.0](https://github.com/epoberezkin/ajv/releases/tag/4.0.0). +[Version 4.0.0](https://github.com/ajv-validator/ajv/releases/tag/4.0.0). -[Version 3.0.0](https://github.com/epoberezkin/ajv/releases/tag/3.0.0). +[Version 3.0.0](https://github.com/ajv-validator/ajv/releases/tag/3.0.0). -[Version 2.0.0](https://github.com/epoberezkin/ajv/releases/tag/2.0.0). +[Version 2.0.0](https://github.com/ajv-validator/ajv/releases/tag/2.0.0). ## Code of conduct -Please review and follow the [Code of conduct](https://github.com/epoberezkin/ajv/blob/master/CODE_OF_CONDUCT.md). +Please review and follow the [Code of conduct](https://github.com/ajv-validator/ajv/blob/master/CODE_OF_CONDUCT.md). Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team. @@ -1457,4 +1457,4 @@ Ajv is a part of [Tidelift subscription](https://tidelift.com/subscription/pkg/n ## License -[MIT](https://github.com/epoberezkin/ajv/blob/master/LICENSE) +[MIT](https://github.com/ajv-validator/ajv/blob/master/LICENSE) diff --git a/bower.json b/bower.json index 048c089b6..507989c62 100644 --- a/bower.json +++ b/bower.json @@ -11,7 +11,7 @@ "schema", "validator" ], - "homepage": "https://github.com/epoberezkin/ajv", + "homepage": "https://github.com/ajv-validator/ajv", "moduleType": [ "amd", "globals", diff --git a/lib/compile/equal.js b/lib/compile/equal.js index 4b271d543..d6c2acef8 100644 --- a/lib/compile/equal.js +++ b/lib/compile/equal.js @@ -1,5 +1,5 @@ 'use strict'; // do NOT remove this file - it would break pre-compiled schemas -// https://github.com/epoberezkin/ajv/issues/889 +// https://github.com/ajv-validator/ajv/issues/889 module.exports = require('fast-deep-equal'); diff --git a/lib/data.js b/lib/data.js index 5f1ad85ef..f11142bec 100644 --- a/lib/data.js +++ b/lib/data.js @@ -38,7 +38,7 @@ module.exports = function (metaSchema, keywordsJsonPointers) { keywords[key] = { anyOf: [ schema, - { $ref: 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#' } + { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' } ] }; } diff --git a/lib/definition_schema.js b/lib/definition_schema.js index e5f6b911c..ad86d4f0b 100644 --- a/lib/definition_schema.js +++ b/lib/definition_schema.js @@ -3,7 +3,7 @@ var metaSchema = require('./refs/json-schema-draft-07.json'); module.exports = { - $id: 'https://github.com/epoberezkin/ajv/blob/master/lib/definition_schema.js', + $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js', definitions: { simpleTypes: metaSchema.definitions.simpleTypes }, diff --git a/lib/keyword.js b/lib/keyword.js index 5fec19a67..06da9a2df 100644 --- a/lib/keyword.js +++ b/lib/keyword.js @@ -46,7 +46,7 @@ function addKeyword(keyword, definition) { metaSchema = { anyOf: [ metaSchema, - { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#' } + { '$ref': 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' } ] }; } diff --git a/lib/refs/data.json b/lib/refs/data.json index 87a2d1437..64aac5b61 100644 --- a/lib/refs/data.json +++ b/lib/refs/data.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#", + "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#", "description": "Meta-schema for $data reference (JSON Schema extension proposal)", "type": "object", "required": [ "$data" ], diff --git a/lib/refs/json-schema-secure.json b/lib/refs/json-schema-secure.json index 66faf84f8..0f7aad479 100644 --- a/lib/refs/json-schema-secure.json +++ b/lib/refs/json-schema-secure.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#", + "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#", "title": "Meta-schema for the security assessment of JSON Schemas", "description": "If a JSON Schema fails validation against this meta-schema, it may be unsafe to validate untrusted data", "definitions": { diff --git a/package.json b/package.json index 0c085c672..10717b435 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/epoberezkin/ajv.git" + "url": "https://github.com/ajv-validator/ajv.git" }, "keywords": [ "JSON", @@ -57,9 +57,9 @@ "author": "Evgeny Poberezkin", "license": "MIT", "bugs": { - "url": "https://github.com/epoberezkin/ajv/issues" + "url": "https://github.com/ajv-validator/ajv/issues" }, - "homepage": "https://github.com/epoberezkin/ajv", + "homepage": "https://github.com/ajv-validator/ajv", "tonicExampleFilename": ".tonic_example.js", "dependencies": { "fast-deep-equal": "^3.1.1", diff --git a/scripts/publish-built-version b/scripts/publish-built-version index 2796ed25f..1b5712372 100755 --- a/scripts/publish-built-version +++ b/scripts/publish-built-version @@ -8,7 +8,7 @@ if [[ -n $TRAVIS_TAG && $TRAVIS_JOB_NUMBER =~ ".3" ]]; then git config user.email "$GIT_USER_EMAIL" git config user.name "$GIT_USER_NAME" - git clone https://${GITHUB_TOKEN}@github.com/epoberezkin/ajv-dist.git ../ajv-dist + git clone https://${GITHUB_TOKEN}@github.com/ajv-validator/ajv-dist.git ../ajv-dist rm -rf ../ajv-dist/dist mkdir ../ajv-dist/dist diff --git a/scripts/travis-gh-pages b/scripts/travis-gh-pages index 46ded1611..b3d4f3d0f 100755 --- a/scripts/travis-gh-pages +++ b/scripts/travis-gh-pages @@ -5,7 +5,7 @@ set -e if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" && $TRAVIS_JOB_NUMBER =~ ".3" ]]; then git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qE '\.md$|^LICENSE$|travis-gh-pages$' && { rm -rf ../gh-pages - git clone -b gh-pages --single-branch https://${GITHUB_TOKEN}@github.com/epoberezkin/ajv.git ../gh-pages + git clone -b gh-pages --single-branch https://${GITHUB_TOKEN}@github.com/ajv-validator/ajv.git ../gh-pages mkdir -p ../gh-pages/_source cp *.md ../gh-pages/_source cp LICENSE ../gh-pages/_source diff --git a/spec/security/array.json b/spec/security/array.json index b089a49bb..25b655f95 100644 --- a/spec/security/array.json +++ b/spec/security/array.json @@ -1,7 +1,7 @@ [ { "description": "uniqueItems without type keyword should be used together with maxItems", - "schema": {"$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#"}, + "schema": {"$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#"}, "tests": [ { "description": "uniqueItems keyword used without maxItems is unsafe", @@ -29,7 +29,7 @@ }, { "description": "uniqueItems with scalar type(s) is safe to use without maxItems", - "schema": {"$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#"}, + "schema": {"$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#"}, "tests": [ { "description": "uniqueItems keyword with a single scalar type is safe", @@ -55,7 +55,7 @@ }, { "description": "uniqueItems with compound type(s) should be used together with maxItems", - "schema": {"$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#"}, + "schema": {"$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#"}, "tests": [ { "description": "uniqueItems keyword with a single compound type and without maxItems is unsafe", diff --git a/spec/security/object.json b/spec/security/object.json index e8efedecb..9de069b8a 100644 --- a/spec/security/object.json +++ b/spec/security/object.json @@ -1,7 +1,7 @@ [ { "description": "patternProperties keyword should be used together with propertyNames", - "schema": { "$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#" }, + "schema": { "$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#" }, "tests": [ { "description": "patternProperties keyword used without propertyNames is unsafe", diff --git a/spec/security/string.json b/spec/security/string.json index 6aa4f861e..c6fb55292 100644 --- a/spec/security/string.json +++ b/spec/security/string.json @@ -1,7 +1,7 @@ [ { "description": "pattern keyword should be used together with maxLength", - "schema": { "$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#" }, + "schema": { "$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#" }, "tests": [ { "description": "pattern keyword used without maxLength is unsafe", @@ -22,7 +22,7 @@ }, { "description": "format keyword should be used together with maxLength", - "schema": { "$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-secure.json#" }, + "schema": { "$ref": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#" }, "tests": [ { "description": "format keyword used without maxLength is unsafe", From 12b683aa5b2a2090251284c1df31ffae09de1da5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 11 May 2020 17:44:52 +0100 Subject: [PATCH 090/127] docs: travis and coveralls links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0f7bda07..9401cfd54 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/07. -[![Build Status](https://travis-ci.org/epoberezkin/ajv.svg?branch=master)](https://travis-ci.org/epoberezkin/ajv) +[![Build Status](https://travis-ci.org/ajv-validator/ajv.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv) [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) -[![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master) +[![Coverage Status](https://coveralls.io/repos/ajv-validator/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/ajv-validator/ajv?branch=master) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) From 7ff7bd9f6ece256bd5020ea92382ffbe90f69994 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 11 May 2020 17:54:25 +0100 Subject: [PATCH 091/127] node version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5862db752..7904fd1eb 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Performance of different validators by [json-schema-benchmark](https://github.co - correct string lengths for strings with unicode pairs (can be turned off) - [formats](#formats) defined by JSON Schema draft-07 standard and custom formats (can be turned off) - [validates schemas against meta-schema](#api-validateschema) -- supports [browsers](#using-in-browser) and Node.js 0.10+ +- supports [browsers](#using-in-browser) and Node.js 0.10-14.x - [asynchronous loading](#asynchronous-schema-compilation) of referenced schemas during compilation - "All errors" validation mode with [option allErrors](#options) - [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages From 0b14f6093d0226405d5dc5fded9736133f34e976 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 11 May 2020 17:59:50 +0100 Subject: [PATCH 092/127] docs: fix coveralls badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a6f44afcd..a8757398e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Build Status](https://travis-ci.org/ajv-validator/ajv.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv) [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) -[![Coverage Status](https://coveralls.io/repos/ajv-validator/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/ajv-validator/ajv?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) From 48d1ca31ebd5d3bfa2dd51e1444b9247096c2086 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 1 Jun 2020 19:54:50 +1200 Subject: [PATCH 093/127] docs: update list of file types supported by `ajvi-cli` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8757398e..8424e171c 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,7 @@ CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-vali - testing expected validity of data against JSON Schema - referenced schemas - custom meta-schemas -- files in JSON and JavaScript format +- files in JSON, JSON5, YAML, and JavaScript format - all Ajv options - reporting changes in data after validation in [JSON-patch](https://tools.ietf.org/html/rfc6902) format From 2ce8002136cf3155aa0ff7fef1c35bc2fdec507f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 5 Jun 2020 08:18:23 +0000 Subject: [PATCH 094/127] Bump typescript from 2.9.2 to 3.9.5 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 2.9.2 to 3.9.5. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v2.9.2...v3.9.5) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10717b435..4cd9f69d5 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", - "typescript": "^2.8.3", + "typescript": "^3.9.5", "uglify-js": "^3.6.9", "watch": "^1.0.0" }, From edd8c92786edf342bdc51d6024e8e75fd0b0da69 Mon Sep 17 00:00:00 2001 From: Issac Gerges Date: Fri, 22 May 2020 11:47:25 -0500 Subject: [PATCH 095/127] Add option for strictNumbers. Resolves #1128. --- README.md | 5 ++- lib/ajv.d.ts | 1 + lib/compile/util.js | 13 ++++--- lib/dot/uniqueItems.jst | 2 +- lib/dot/validate.jst | 4 +-- spec/options/strictNumbers.spec.js | 55 ++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 spec/options/strictNumbers.spec.js diff --git a/README.md b/README.md index a8757398e..98f5991b2 100644 --- a/README.md +++ b/README.md @@ -1156,6 +1156,7 @@ Defaults: // strict mode options strictDefaults: false, strictKeywords: false, + strictNumbers: false, // asynchronous validation options: transpile: undefined, // requires ajv-async package // advanced options: @@ -1250,7 +1251,9 @@ Defaults: - `false` (default) - unknown keywords are not reported - `true` - if an unknown keyword is present, throw an error - `"log"` - if an unknown keyword is present, log warning - +- _strictNumbers_: validate numbers strictly, failing validation for NaN and Infinity. Option values: + - `false` (default) - NaN or Infinity will pass validation for numeric types + - `true` - NaN or Infinity will not pass validation for numeric types ##### Asynchronous validation options diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index d988c3a99..cc2881b33 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -183,6 +183,7 @@ declare namespace ajv { coerceTypes?: boolean | 'array'; strictDefaults?: boolean | 'log'; strictKeywords?: boolean | 'log'; + strictNumbers?: boolean; async?: boolean | string; transpile?: string | ((code: string) => string); meta?: boolean | object; diff --git a/lib/compile/util.js b/lib/compile/util.js index 0efa00111..702f6e19d 100644 --- a/lib/compile/util.js +++ b/lib/compile/util.js @@ -36,7 +36,7 @@ function copy(o, to) { } -function checkDataType(dataType, data, negate) { +function checkDataType(dataType, data, strictNumbers, negate) { var EQUAL = negate ? ' !== ' : ' === ' , AND = negate ? ' || ' : ' && ' , OK = negate ? '!' : '' @@ -49,15 +49,18 @@ function checkDataType(dataType, data, negate) { NOT + 'Array.isArray(' + data + '))'; case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND + NOT + '(' + data + ' % 1)' + - AND + data + EQUAL + data + ')'; + AND + data + EQUAL + data + + (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')'; + case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' + + (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')'; default: return 'typeof ' + data + EQUAL + '"' + dataType + '"'; } } -function checkDataTypes(dataTypes, data) { +function checkDataTypes(dataTypes, data, strictNumbers) { switch (dataTypes.length) { - case 1: return checkDataType(dataTypes[0], data, true); + case 1: return checkDataType(dataTypes[0], data, strictNumbers, true); default: var code = ''; var types = toHash(dataTypes); @@ -70,7 +73,7 @@ function checkDataTypes(dataTypes, data) { } if (types.number) delete types.integer; for (var t in types) - code += (code ? ' && ' : '' ) + checkDataType(t, data, true); + code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true); return code; } diff --git a/lib/dot/uniqueItems.jst b/lib/dot/uniqueItems.jst index 22f82f99d..e69b8308d 100644 --- a/lib/dot/uniqueItems.jst +++ b/lib/dot/uniqueItems.jst @@ -38,7 +38,7 @@ for (;i--;) { var item = {{=$data}}[i]; {{ var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); }} - if ({{= it.util[$method]($itemType, 'item', true) }}) continue; + if ({{= it.util[$method]($itemType, 'item', it.opts.strictNumbers, true) }}) continue; {{? $typeIsArray}} if (typeof item == 'string') item = '"' + item; {{?}} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index f8a1edfc0..bae653ff6 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -140,7 +140,7 @@ , $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType'; }} - if ({{= it.util[$method]($typeSchema, $data, true) }}) { + if ({{= it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true) }}) { #}} {{? it.schema.$ref && $refKeywords }} @@ -192,7 +192,7 @@ {{~ it.RULES:$rulesGroup }} {{? $shouldUseGroup($rulesGroup) }} {{? $rulesGroup.type }} - if ({{= it.util.checkDataType($rulesGroup.type, $data) }}) { + if ({{= it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers) }}) { {{?}} {{? it.opts.useDefaults }} {{? $rulesGroup.type == 'object' && it.schema.properties }} diff --git a/spec/options/strictNumbers.spec.js b/spec/options/strictNumbers.spec.js new file mode 100644 index 000000000..adf63b026 --- /dev/null +++ b/spec/options/strictNumbers.spec.js @@ -0,0 +1,55 @@ +'use strict'; + +var Ajv = require('../ajv'); + +describe('structNumbers option', function() { + var ajv; + describe('strictNumbers default', testWithoutStrictNumbers(new Ajv())); + describe('strictNumbers = false', testWithoutStrictNumbers(new Ajv({strictNumbers: false}))); + describe('strictNumbers = true', function() { + beforeEach(function () { + ajv = new Ajv({strictNumbers: true}); + }); + + it('should fail validation for NaN/Infinity as type number', function() { + var validate = ajv.compile({type: 'number'}); + validate("1.1").should.equal(false); + validate(1.1).should.equal(true); + validate(1).should.equal(true); + validate(NaN).should.equal(false); + validate(Infinity).should.equal(false); + }); + + it('should fail validation for NaN as type integer', function() { + var validate = ajv.compile({type: 'integer'}); + validate("1.1").should.equal(false); + validate(1.1).should.equal(false); + validate(1).should.equal(true); + validate(NaN).should.equal(false); + validate(Infinity).should.equal(false); + }); + }); +}); + + +function testWithoutStrictNumbers(_ajv) { + return function () { + it('should NOT fail validation for NaN/Infinity as type number', function() { + var validate = _ajv.compile({type: 'number'}); + validate("1.1").should.equal(false); + validate(1.1).should.equal(true); + validate(1).should.equal(true); + validate(NaN).should.equal(true); + validate(Infinity).should.equal(true); + }); + + it('should NOT fail validation for NaN/Infinity as type integer', function() { + var validate = _ajv.compile({type: 'integer'}); + validate("1.1").should.equal(false); + validate(1.1).should.equal(false); + validate(1).should.equal(true); + validate(NaN).should.equal(false); + validate(Infinity).should.equal(true); + }); + }; +} From 854dbefa5a4006f8070cca9f2af9674ee1eb9b06 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2020 08:36:33 +0000 Subject: [PATCH 096/127] Bump mocha from 7.2.0 to 8.0.1 Bumps [mocha](https://github.com/mochajs/mocha) from 7.2.0 to 8.0.1. - [Release notes](https://github.com/mochajs/mocha/releases) - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md) - [Commits](https://github.com/mochajs/mocha/compare/v7.2.0...v8.0.1) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4cd9f69d5..d3215f120 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^2.0.0", "karma-sauce-launcher": "^4.1.3", - "mocha": "^7.0.1", + "mocha": "^8.0.1", "nyc": "^15.0.0", "pre-commit": "^1.1.1", "require-globify": "^1.3.0", From 54c96b05e633b699b2eb07de580d0851024d162e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 23 Jun 2020 08:44:24 +0000 Subject: [PATCH 097/127] Bump eslint from 6.8.0 to 7.3.1 Bumps [eslint](https://github.com/eslint/eslint) from 6.8.0 to 7.3.1. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v6.8.0...v7.3.1) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4cd9f69d5..84be93923 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "coveralls": "^3.0.1", "del-cli": "^3.0.0", "dot": "^1.0.3", - "eslint": "^6.0.0", + "eslint": "^7.3.1", "gh-pages-generator": "^0.2.3", "glob": "^7.0.0", "if-node-version": "^1.0.0", From e7f0c81c136a06b3e08c742b75828bf6071a2ddb Mon Sep 17 00:00:00 2001 From: Vadim Cebaniuc Date: Sat, 27 Jun 2020 19:18:52 +0300 Subject: [PATCH 098/127] Fix mistype in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10487a386..c340f339c 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ You can add additional formats and replace any of the formats above using [addFo The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can whitelist specific format(s) to be ignored. See [Options](#options) for details. -You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validatorv/ajv/blob/master/lib/compile/formats.js). +You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js). ## Combining schemas with $ref From 0006f34ce5eab2d233154aee4b8f5715f298c030 Mon Sep 17 00:00:00 2001 From: Graham Lea Date: Tue, 30 Jun 2020 17:33:03 +1000 Subject: [PATCH 099/127] Document pre-compiled schemas for CSP in README Pre-compiled schemas are a workaround for maintaining a secure Content Security Policy (CSP) Fixes #1228 --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c340f339c..bae892d27 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,15 @@ Ajv is tested with these browsers: __Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)). +### Ajv & Content Security Policies (CSP) + +If you're using Ajv to compile a schema (the typical use) in a browser document that is loaded with a Content Security Policy (CSP), that policy will require a `script-src` directive that includes the value `'unsafe-eval'`. +:warning: NOTE, however, that `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks. + +In order to make use of Ajv without easing your CSP, you can [pre-compile a schema using the CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas). This will transpile the schema JSON into a JavaScript file that exports a `validate` function that works simlarly to a schema compiled at runtime. +Note that the pre-compiled schemas, which are created using [ajv-pack](https://github.com/ajv-validator/ajv-pack#limitations), are not functionally equivalent to Ajv and there are known limitations. + + ## Command line interface CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports: From c581ff3dc1cc6e0acb39e16e2b0f2bcce5dc8857 Mon Sep 17 00:00:00 2001 From: Graham Lea Date: Tue, 30 Jun 2020 21:24:29 +1000 Subject: [PATCH 100/127] Clarify limitations of ajv-pack in README Fixes #1228 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bae892d27..7d2b1f0ea 100644 --- a/README.md +++ b/README.md @@ -238,13 +238,14 @@ Ajv is tested with these browsers: __Please note__: some frameworks, e.g. Dojo, may redefine global require in such way that is not compatible with CommonJS module format. In such case Ajv bundle has to be loaded before the framework and then you can use global Ajv (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)). -### Ajv & Content Security Policies (CSP) +### Ajv and Content Security Policies (CSP) If you're using Ajv to compile a schema (the typical use) in a browser document that is loaded with a Content Security Policy (CSP), that policy will require a `script-src` directive that includes the value `'unsafe-eval'`. :warning: NOTE, however, that `unsafe-eval` is NOT recommended in a secure CSP[[1]](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval), as it has the potential to open the document to cross-site scripting (XSS) attacks. In order to make use of Ajv without easing your CSP, you can [pre-compile a schema using the CLI](https://github.com/ajv-validator/ajv-cli#compile-schemas). This will transpile the schema JSON into a JavaScript file that exports a `validate` function that works simlarly to a schema compiled at runtime. -Note that the pre-compiled schemas, which are created using [ajv-pack](https://github.com/ajv-validator/ajv-pack#limitations), are not functionally equivalent to Ajv and there are known limitations. + +Note that pre-compilation of schemas is performed using [ajv-pack](https://github.com/ajv-validator/ajv-pack) and there are [some limitations to the schema features it can compile](https://github.com/ajv-validator/ajv-pack#limitations). A successfully pre-compiled schema is equivalent to the same schema compiled at runtime. ## Command line interface From 0e2c3463a28ac19b5ea8324511889540c41125fa Mon Sep 17 00:00:00 2001 From: Graham Lea Date: Tue, 30 Jun 2020 21:26:54 +1000 Subject: [PATCH 101/127] Add Contents link to CSP section Fixes #1228 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7d2b1f0ea..29beb7286 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); - [Getting started](#getting-started) - [Frequently Asked Questions](https://github.com/ajv-validator/ajv/blob/master/FAQ.md) - [Using in browser](#using-in-browser) + - [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp) - [Command line interface](#command-line-interface) - Validation - [Keywords](#validation-keywords) From fd64fb4c939c6f6b8d68aa4c6c57d8be8cc1994d Mon Sep 17 00:00:00 2001 From: Graham Lea Date: Tue, 30 Jun 2020 21:31:56 +1000 Subject: [PATCH 102/127] Add link to CSP section in Security section Fixes #1228 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 29beb7286..5e502db93 100644 --- a/README.md +++ b/README.md @@ -733,6 +733,10 @@ isSchemaSecure(schema2); // true __Please note__: following all these recommendation is not a guarantee that validation of untrusted data is safe - it can still lead to some undesirable results. +##### Content Security Policies (CSP) +See [Ajv and Content Security Policies (CSP)](#ajv-and-content-security-policies-csp) + + ## ReDoS attack Certain regular expressions can lead to the exponential evaluation time even with relatively short strings. From 24d4f8fd8f812051bce521454c5152b87eb27c9c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:26:25 +0100 Subject: [PATCH 103/127] remove code post-processing --- lib/compile/util.js | 38 --------------------------- lib/dot/allOf.jst | 2 -- lib/dot/anyOf.jst | 2 -- lib/dot/contains.jst | 2 -- lib/dot/definitions.def | 6 ----- lib/dot/dependencies.jst | 2 -- lib/dot/if.jst | 2 -- lib/dot/items.jst | 2 -- lib/dot/properties.jst | 2 -- lib/dot/propertyNames.jst | 2 -- lib/dot/validate.jst | 6 ----- spec/issues/388_code_clean-up.spec.js | 28 -------------------- 12 files changed, 94 deletions(-) delete mode 100644 spec/issues/388_code_clean-up.spec.js diff --git a/lib/compile/util.js b/lib/compile/util.js index 702f6e19d..f232a6fb1 100644 --- a/lib/compile/util.js +++ b/lib/compile/util.js @@ -13,8 +13,6 @@ module.exports = { ucs2length: require('./ucs2length'), varOccurences: varOccurences, varReplace: varReplace, - cleanUpCode: cleanUpCode, - finalCleanUpCode: finalCleanUpCode, schemaHasRules: schemaHasRules, schemaHasRulesExcept: schemaHasRulesExcept, schemaUnknownRules: schemaUnknownRules, @@ -139,42 +137,6 @@ function varReplace(str, dataVar, expr) { } -var EMPTY_ELSE = /else\s*{\s*}/g - , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g - , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g; -function cleanUpCode(out) { - return out.replace(EMPTY_ELSE, '') - .replace(EMPTY_IF_NO_ELSE, '') - .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))'); -} - - -var ERRORS_REGEXP = /[^v.]errors/g - , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g - , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g - , RETURN_VALID = 'return errors === 0;' - , RETURN_TRUE = 'validate.errors = null; return true;' - , RETURN_ASYNC = /if \(errors === 0\) return data;\s*else throw new ValidationError\(vErrors\);/ - , RETURN_DATA_ASYNC = 'return data;' - , ROOTDATA_REGEXP = /[^A-Za-z_$]rootData[^A-Za-z0-9_$]/g - , REMOVE_ROOTDATA = /if \(rootData === undefined\) rootData = data;/; - -function finalCleanUpCode(out, async) { - var matches = out.match(ERRORS_REGEXP); - if (matches && matches.length == 2) { - out = async - ? out.replace(REMOVE_ERRORS_ASYNC, '') - .replace(RETURN_ASYNC, RETURN_DATA_ASYNC) - : out.replace(REMOVE_ERRORS, '') - .replace(RETURN_VALID, RETURN_TRUE); - } - - matches = out.match(ROOTDATA_REGEXP); - if (!matches || matches.length !== 3) return out; - return out.replace(REMOVE_ROOTDATA, ''); -} - - function schemaHasRules(schema, rules) { if (typeof schema == 'boolean') return !schema; for (var key in schema) if (rules[key]) return true; diff --git a/lib/dot/allOf.jst b/lib/dot/allOf.jst index 4c2836311..0e782fe98 100644 --- a/lib/dot/allOf.jst +++ b/lib/dot/allOf.jst @@ -30,5 +30,3 @@ {{= $closingBraces.slice(0,-1) }} {{?}} {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/anyOf.jst b/lib/dot/anyOf.jst index 086cf2b33..ea909ee62 100644 --- a/lib/dot/anyOf.jst +++ b/lib/dot/anyOf.jst @@ -39,8 +39,6 @@ } else { {{# def.resetErrors }} {{? it.opts.allErrors }} } {{?}} - - {{# def.cleanUp }} {{??}} {{? $breakOnError }} if (true) { diff --git a/lib/dot/contains.jst b/lib/dot/contains.jst index 925d2c84b..4dc996741 100644 --- a/lib/dot/contains.jst +++ b/lib/dot/contains.jst @@ -53,5 +53,3 @@ var {{=$valid}}; {{# def.resetErrors }} {{?}} {{? it.opts.allErrors }} } {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/definitions.def b/lib/dot/definitions.def index b68e064e8..162231a8e 100644 --- a/lib/dot/definitions.def +++ b/lib/dot/definitions.def @@ -112,12 +112,6 @@ #}} -{{## def.cleanUp: {{ out = it.util.cleanUpCode(out); }} #}} - - -{{## def.finalCleanUp: {{ out = it.util.finalCleanUpCode(out, $async); }} #}} - - {{## def.$data: {{ var $isData = it.opts.$data && $schema && $schema.$data diff --git a/lib/dot/dependencies.jst b/lib/dot/dependencies.jst index c41f33422..9ff68a78d 100644 --- a/lib/dot/dependencies.jst +++ b/lib/dot/dependencies.jst @@ -76,5 +76,3 @@ var missing{{=$lvl}}; {{= $closingBraces }} if ({{=$errs}} == errors) { {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/if.jst b/lib/dot/if.jst index 7ccc9b7f7..adb503612 100644 --- a/lib/dot/if.jst +++ b/lib/dot/if.jst @@ -65,8 +65,6 @@ {{# def.extraError:'if' }} } {{? $breakOnError }} else { {{?}} - - {{# def.cleanUp }} {{??}} {{? $breakOnError }} if (true) { diff --git a/lib/dot/items.jst b/lib/dot/items.jst index 8c0f5acb5..acc932a26 100644 --- a/lib/dot/items.jst +++ b/lib/dot/items.jst @@ -96,5 +96,3 @@ var {{=$valid}}; {{= $closingBraces }} if ({{=$errs}} == errors) { {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/properties.jst b/lib/dot/properties.jst index 862067e75..f3de23650 100644 --- a/lib/dot/properties.jst +++ b/lib/dot/properties.jst @@ -240,5 +240,3 @@ var {{=$nextValid}} = true; {{= $closingBraces }} if ({{=$errs}} == errors) { {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/propertyNames.jst b/lib/dot/propertyNames.jst index ee52b2151..d456ccafc 100644 --- a/lib/dot/propertyNames.jst +++ b/lib/dot/propertyNames.jst @@ -50,5 +50,3 @@ var {{=$errs}} = errors; {{= $closingBraces }} if ({{=$errs}} == errors) { {{?}} - -{{# def.cleanUp }} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index bae653ff6..fd833a535 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -254,12 +254,6 @@ var {{=$valid}} = errors === errs_{{=$lvl}}; {{?}} -{{# def.cleanUp }} - -{{? $top }} - {{# def.finalCleanUp }} -{{?}} - {{ function $shouldUseGroup($rulesGroup) { var rules = $rulesGroup.rules; diff --git a/spec/issues/388_code_clean-up.spec.js b/spec/issues/388_code_clean-up.spec.js deleted file mode 100644 index 9a0288362..000000000 --- a/spec/issues/388_code_clean-up.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var Ajv = require('../ajv'); -var should = require('../chai').should(); - - -describe('issue #388, code clean-up not working', function() { - it('should remove assignement to rootData if it is not used', function() { - var ajv = new Ajv; - var validate = ajv.compile({ - type: 'object', - properties: { - foo: { type: 'string' } - } - }); - var code = validate.toString(); - code.match(/rootData/g).length .should.equal(1); - }); - - it('should remove assignement to errors if they are not used', function() { - var ajv = new Ajv; - var validate = ajv.compile({ - type: 'object' - }); - var code = validate.toString(); - should.equal(code.match(/[^.]errors|vErrors/g), null); - }); -}); From 65b2f7d76b190ac63a0d4e9154c712d7aa37049f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 30 Jun 2020 19:30:48 +0100 Subject: [PATCH 104/127] validate numbers in schemas during schema compilation --- lib/dot/_limit.jst | 9 ++++++++ lib/dot/_limitItems.jst | 2 ++ lib/dot/_limitLength.jst | 2 ++ lib/dot/_limitProperties.jst | 2 ++ lib/dot/definitions.def | 7 ++++++ spec/ajv.spec.js | 44 ++++++++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+) diff --git a/lib/dot/_limit.jst b/lib/dot/_limit.jst index e10806fd3..f15218922 100644 --- a/lib/dot/_limit.jst +++ b/lib/dot/_limit.jst @@ -17,6 +17,15 @@ , $op = $isMax ? '<' : '>' , $notOp = $isMax ? '>' : '<' , $errorKeyword = undefined; + + if (!($isData || typeof $schema == 'number' || $schema === undefined)) { + throw new Error($keyword + ' must be number'); + } + if (!($isDataExcl || $schemaExcl === undefined + || typeof $schemaExcl == 'number' + || typeof $schemaExcl == 'boolean')) { + throw new Error($exclusiveKeyword + ' must be number or boolean'); + } }} {{? $isDataExcl }} diff --git a/lib/dot/_limitItems.jst b/lib/dot/_limitItems.jst index a3e078e51..741329e77 100644 --- a/lib/dot/_limitItems.jst +++ b/lib/dot/_limitItems.jst @@ -3,6 +3,8 @@ {{# def.setupKeyword }} {{# def.$data }} +{{# def.numberKeyword }} + {{ var $op = $keyword == 'maxItems' ? '>' : '<'; }} if ({{# def.$dataNotType:'number' }} {{=$data}}.length {{=$op}} {{=$schemaValue}}) { {{ var $errorKeyword = $keyword; }} diff --git a/lib/dot/_limitLength.jst b/lib/dot/_limitLength.jst index cfc8dbb01..285c66bd2 100644 --- a/lib/dot/_limitLength.jst +++ b/lib/dot/_limitLength.jst @@ -3,6 +3,8 @@ {{# def.setupKeyword }} {{# def.$data }} +{{# def.numberKeyword }} + {{ var $op = $keyword == 'maxLength' ? '>' : '<'; }} if ({{# def.$dataNotType:'number' }} {{# def.strLength }} {{=$op}} {{=$schemaValue}}) { {{ var $errorKeyword = $keyword; }} diff --git a/lib/dot/_limitProperties.jst b/lib/dot/_limitProperties.jst index da7ea776f..c4c21551a 100644 --- a/lib/dot/_limitProperties.jst +++ b/lib/dot/_limitProperties.jst @@ -3,6 +3,8 @@ {{# def.setupKeyword }} {{# def.$data }} +{{# def.numberKeyword }} + {{ var $op = $keyword == 'maxProperties' ? '>' : '<'; }} if ({{# def.$dataNotType:'number' }} Object.keys({{=$data}}).length {{=$op}} {{=$schemaValue}}) { {{ var $errorKeyword = $keyword; }} diff --git a/lib/dot/definitions.def b/lib/dot/definitions.def index 162231a8e..db4ea6f32 100644 --- a/lib/dot/definitions.def +++ b/lib/dot/definitions.def @@ -138,6 +138,13 @@ #}} +{{## def.numberKeyword: + {{? !($isData || typeof $schema == 'number') }} + {{ throw new Error($keyword + ' must be number'); }} + {{?}} +#}} + + {{## def.beginDefOut: {{ var $$outStack = $$outStack || []; diff --git a/spec/ajv.spec.js b/spec/ajv.spec.js index e3bf766b7..88cf13a74 100644 --- a/spec/ajv.spec.js +++ b/spec/ajv.spec.js @@ -512,5 +512,49 @@ describe('Ajv', function () { }); }); }); + + describe('sub-schema validation outside of definitions during compilation', function() { + it('maximum', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {maximum: 'bar'} + }); + }); + + it('exclusiveMaximum', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {exclusiveMaximum: 'bar'} + }); + }); + + it('maxItems', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {maxItems: 'bar'} + }); + }); + + it('maxLength', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {maxLength: 'bar'} + }); + }); + + it('maxProperties', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {maxProperties: 'bar'} + }); + }); + + function passValidationThrowCompile(schema) { + ajv.validateSchema(schema) .should.equal(true); + should.throw(function() { + ajv.compile(schema); + }); + } + }); }); }); From 1105fd5ad9afdb08656db33ba222191036870785 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 30 Jun 2020 19:56:19 +0100 Subject: [PATCH 105/127] ignore proto properties --- lib/dot/properties.jst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/dot/properties.jst b/lib/dot/properties.jst index f3de23650..5cebb9b12 100644 --- a/lib/dot/properties.jst +++ b/lib/dot/properties.jst @@ -28,9 +28,9 @@ , $nextData = 'data' + $dataNxt , $dataProperties = 'dataProperties' + $lvl; - var $schemaKeys = Object.keys($schema || {}) + var $schemaKeys = Object.keys($schema || {}).filter(notProto) , $pProperties = it.schema.patternProperties || {} - , $pPropertyKeys = Object.keys($pProperties) + , $pPropertyKeys = Object.keys($pProperties).filter(notProto) , $aProperties = it.schema.additionalProperties , $someProperties = $schemaKeys.length || $pPropertyKeys.length , $noAdditional = $aProperties === false @@ -42,8 +42,11 @@ , $currentBaseId = it.baseId; var $required = it.schema.required; - if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) + if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) { var $requiredHash = it.util.toHash($required); + } + + function notProto(p) { return p !== '__proto__'; } }} From 9c009a96ab9b2289211b3ed20a0b5fad4b8defe8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 1 Jul 2020 10:00:58 +0100 Subject: [PATCH 106/127] validate numbers in multipleOf --- lib/dot/multipleOf.jst | 2 ++ spec/ajv.spec.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/dot/multipleOf.jst b/lib/dot/multipleOf.jst index 5f8dd33b5..6d88a456f 100644 --- a/lib/dot/multipleOf.jst +++ b/lib/dot/multipleOf.jst @@ -3,6 +3,8 @@ {{# def.setupKeyword }} {{# def.$data }} +{{# def.numberKeyword }} + var division{{=$lvl}}; if ({{?$isData}} {{=$schemaValue}} !== undefined && ( diff --git a/spec/ajv.spec.js b/spec/ajv.spec.js index 88cf13a74..118a827ad 100644 --- a/spec/ajv.spec.js +++ b/spec/ajv.spec.js @@ -549,6 +549,13 @@ describe('Ajv', function () { }); }); + it('multipleOf', function() { + passValidationThrowCompile({ + $ref: '#/foo', + foo: {maxProperties: 'bar'} + }); + }); + function passValidationThrowCompile(schema) { ajv.validateSchema(schema) .should.equal(true); should.throw(function() { From 68d72c41d5eca933404cfcf909856b61ab3b6251 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 1 Jul 2020 10:42:57 +0100 Subject: [PATCH 107/127] update regex --- lib/compile/util.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/compile/util.js b/lib/compile/util.js index f232a6fb1..5d54e2efb 100644 --- a/lib/compile/util.js +++ b/lib/compile/util.js @@ -137,6 +137,8 @@ function varReplace(str, dataVar, expr) { } + + function schemaHasRules(schema, rules) { if (typeof schema == 'boolean') return !schema; for (var key in schema) if (rules[key]) return true; @@ -215,7 +217,7 @@ function getData($data, lvl, paths) { function joinPaths (a, b) { if (a == '""') return b; - return (a + ' + ' + b).replace(/' \+ '/g, ''); + return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1'); } From f2b1e3d2c89288561ee68d7459a41b7222cc520d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:25:30 +0100 Subject: [PATCH 108/127] whitespace --- lib/compile/util.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/compile/util.js b/lib/compile/util.js index 5d54e2efb..ef07b8c75 100644 --- a/lib/compile/util.js +++ b/lib/compile/util.js @@ -137,8 +137,6 @@ function varReplace(str, dataVar, expr) { } - - function schemaHasRules(schema, rules) { if (typeof schema == 'boolean') return !schema; for (var key in schema) if (rules[key]) return true; From 988982d3fde08e3ea074e8942442834e78c45587 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:56:05 +0100 Subject: [PATCH 109/127] ignore proto properties --- lib/dot/dependencies.jst | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dot/dependencies.jst b/lib/dot/dependencies.jst index 9ff68a78d..e4bdddec8 100644 --- a/lib/dot/dependencies.jst +++ b/lib/dot/dependencies.jst @@ -19,6 +19,7 @@ , $ownProperties = it.opts.ownProperties; for ($property in $schema) { + if ($property == '__proto__') continue; var $sch = $schema[$property]; var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps; $deps[$property] = $sch; From d6aabb8e97029130cdb607dcd2e78a6d567e10d5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Jul 2020 14:01:07 +0100 Subject: [PATCH 110/127] test: remove node 8 from travis test --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 11a0afa18..80bb5bf49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ before_script: - git submodule update --init - npm install -g codeclimate-test-reporter node_js: - - 8 - 10 - 12 - 14 From 521c3a53f15f5502fb4a734194932535d311267c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Jul 2020 16:44:23 +0100 Subject: [PATCH 111/127] 6.12.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db0849ea8..c2a1c1f8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.2", + "version": "6.12.3", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From c34840c8a8424786e62ec4b25299b4d53ac465ca Mon Sep 17 00:00:00 2001 From: "Geerts, Ryan J" Date: Fri, 17 Jul 2020 10:39:23 -0500 Subject: [PATCH 112/127] improved language to be more inclusive for less privileged populations --- README.md | 2 +- spec/extras/$data/format.json | 4 ++-- spec/options/unknownFormats.spec.js | 4 ++-- spec/tests/rules/format.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5e502db93..6a82be93e 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ There are two modes of format validation: `fast` and `full`. This mode affects f You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method. -The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can whitelist specific format(s) to be ignored. See [Options](#options) for details. +The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allowlist specific format(s) to be ignored. See [Options](#options) for details. You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js). diff --git a/spec/extras/$data/format.json b/spec/extras/$data/format.json index 22cac2ddc..b223fb92b 100644 --- a/spec/extras/$data/format.json +++ b/spec/extras/$data/format.json @@ -49,7 +49,7 @@ "valid": false }, { - "description": "whitelisted unknown format is valid", + "description": "allowlisted unknown format is valid", "data": { "str": "any value", "strFormat": "allowedUnknown" @@ -57,7 +57,7 @@ "valid": true }, { - "description": "not whitelisted unknown format is invalid", + "description": "not allowlisted unknown format is invalid", "data": { "str": "any value", "strFormat": "completelyUnknown" diff --git a/spec/options/unknownFormats.spec.js b/spec/options/unknownFormats.spec.js index 81ea32655..018575140 100644 --- a/spec/options/unknownFormats.spec.js +++ b/spec/options/unknownFormats.spec.js @@ -70,7 +70,7 @@ describe('unknownFormats option', function() { }); describe('= [String]', function() { - it('should pass schema compilation and be valid if whitelisted unknown format is used', function() { + it('should pass schema compilation and be valid if alloylisted unknown format is used', function() { test(new Ajv({unknownFormats: ['allowed']})); function test(ajv) { @@ -83,7 +83,7 @@ describe('unknownFormats option', function() { } }); - it('should be valid if whitelisted unknown format is used via $data', function() { + it('should be valid if alloylisted unknown format is used via $data', function() { test(new Ajv({$data: true, unknownFormats: ['allowed']})); function test(ajv) { diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index c316a6ee5..c7d2b07f0 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -1,6 +1,6 @@ [ { - "description": "whitelisted unknown format is valid", + "description": "alloylisted unknown format is valid", "schema": { "format": "allowedUnknown" }, From bf63684e820524990fe9980f5e8310019cb0f91f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 18 Jul 2020 19:46:20 +0100 Subject: [PATCH 113/127] allowed unknown formats --- README.md | 2 +- spec/extras/$data/format.json | 16 +++++++++++----- spec/options/unknownFormats.spec.js | 4 ++-- spec/tests/rules/format.json | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6a82be93e..ce4507fdb 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ There are two modes of format validation: `fast` and `full`. This mode affects f You can add additional formats and replace any of the formats above using [addFormat](#api-addformat) method. -The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allowlist specific format(s) to be ignored. See [Options](#options) for details. +The option `unknownFormats` allows changing the default behaviour when an unknown format is encountered. In this case Ajv can either fail schema compilation (default) or ignore it (default in versions before 5.0.0). You also can allow specific format(s) that will be ignored. See [Options](#options) for details. You can find regular expressions used for format validation and the sources that were used in [formats.js](https://github.com/ajv-validator/ajv/blob/master/lib/compile/formats.js). diff --git a/spec/extras/$data/format.json b/spec/extras/$data/format.json index b223fb92b..97c7fa797 100644 --- a/spec/extras/$data/format.json +++ b/spec/extras/$data/format.json @@ -3,7 +3,11 @@ "description": "one property has format set in another property", "schema": { "properties": { - "str": { "format": { "$data": "1/strFormat" } }, + "str": { + "format": { + "$data": "1/strFormat" + } + }, "strFormat": {} } }, @@ -49,7 +53,7 @@ "valid": false }, { - "description": "allowlisted unknown format is valid", + "description": "allowed unknown format is valid", "data": { "str": "any value", "strFormat": "allowedUnknown" @@ -57,7 +61,7 @@ "valid": true }, { - "description": "not allowlisted unknown format is invalid", + "description": "unknown format is invalid", "data": { "str": "any value", "strFormat": "completelyUnknown" @@ -85,7 +89,9 @@ "description": "property name is the format for the property value", "schema": { "additionalProperties": { - "format": { "$data": "0#" } + "format": { + "$data": "0#" + } } }, "tests": [ @@ -115,4 +121,4 @@ } ] } -] +] \ No newline at end of file diff --git a/spec/options/unknownFormats.spec.js b/spec/options/unknownFormats.spec.js index 018575140..6e6dfde3d 100644 --- a/spec/options/unknownFormats.spec.js +++ b/spec/options/unknownFormats.spec.js @@ -70,7 +70,7 @@ describe('unknownFormats option', function() { }); describe('= [String]', function() { - it('should pass schema compilation and be valid if alloylisted unknown format is used', function() { + it('should pass schema compilation and be valid if allowed unknown format is used', function() { test(new Ajv({unknownFormats: ['allowed']})); function test(ajv) { @@ -83,7 +83,7 @@ describe('unknownFormats option', function() { } }); - it('should be valid if alloylisted unknown format is used via $data', function() { + it('should be valid if allowed unknown format is used via $data', function() { test(new Ajv({$data: true, unknownFormats: ['allowed']})); function test(ajv) { diff --git a/spec/tests/rules/format.json b/spec/tests/rules/format.json index c7d2b07f0..433a0aaf8 100644 --- a/spec/tests/rules/format.json +++ b/spec/tests/rules/format.json @@ -1,6 +1,6 @@ [ { - "description": "alloylisted unknown format is valid", + "description": "allowed unknown format is valid", "schema": { "format": "allowedUnknown" }, From 981317c2f3862ab2069d8d9e3220bb4ac6c8699d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 22 Jul 2020 13:55:04 +0300 Subject: [PATCH 114/127] Fix uri scheme validation `foo,bar:baz` is not a valid uri. Refs: https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/419 --- lib/compile/formats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 44895b0b4..7726ee326 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -36,8 +36,8 @@ formats.fast = { time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js - uri: /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i, - 'uri-reference': /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, + uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i, + 'uri-reference': /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i, 'uri-template': URITEMPLATE, url: URL, // email (sources from jsen validator): From d4d1a13182f8f637971d0b8adbc640415a000c55 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 13 Aug 2020 21:00:48 +0100 Subject: [PATCH 115/127] test: failing coercion tests with option coerceTypes: array --- spec/coercion.spec.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/coercion.spec.js b/spec/coercion.spec.js index a9f13de5c..1a8426af1 100644 --- a/spec/coercion.spec.js +++ b/spec/coercion.spec.js @@ -144,12 +144,17 @@ var coercionArrayRules = JSON.parse(JSON.stringify(coercionRules)); coercionArrayRules.string.array = [ { from: ['abc'], to: 'abc' }, { from: [123], to: '123' }, + { from: [true], to: 'true'}, + { from: [null], to: ''}, { from: ['abc', 'def'], to: undefined }, { from: [], to: undefined } ]; coercionArrayRules.number.array = [ { from: [1.5], to: 1.5 }, - { from: ['1.5'], to: 1.5 } + { from: ['1.5'], to: 1.5 }, + { from: [true], to: 1 }, + { from: [null], to: 0 }, + // { from: ['abc'], to: undefined }, ]; coercionArrayRules.integer.array = [ { from: [1], to: 1 }, @@ -160,13 +165,16 @@ coercionArrayRules.integer.array = [ coercionArrayRules.boolean.array = [ { from: [true], to: true }, { from: ['true'], to: true }, - { from: [1], to: true } + { from: [1], to: true }, + // { from: ['abc'], to: undefined }, + // { from: [2], to: undefined }, ]; coercionArrayRules.null.array = [ { from: [null], to: null }, { from: [''], to: null }, { from: [0], to: null }, - { from: [false], to: null } + { from: [false], to: null }, + // {from: [true], to: undefined}, ]; coercionArrayRules.object.array = [ { from: [{}], to: undefined } From 73f612f100f2ae3ccc813a56d09b74593e3fed80 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 14 Aug 2020 13:17:07 +0100 Subject: [PATCH 116/127] fix: coercion of array to scalar that should fail validation --- lib/dot/coerce.def | 46 +++++++++++++++++-------------------------- spec/coercion.spec.js | 22 +++++++++++++++------ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/dot/coerce.def b/lib/dot/coerce.def index 86e0e18af..c947ed6af 100644 --- a/lib/dot/coerce.def +++ b/lib/dot/coerce.def @@ -4,55 +4,45 @@ , $coerced = 'coerced' + $lvl; }} var {{=$dataType}} = typeof {{=$data}}; - {{? it.opts.coerceTypes == 'array'}} - if ({{=$dataType}} == 'object' && Array.isArray({{=$data}})) {{=$dataType}} = 'array'; - {{?}} - var {{=$coerced}} = undefined; - {{ var $bracesCoercion = ''; }} - {{~ $coerceToTypes:$type:$i }} - {{? $i }} - if ({{=$coerced}} === undefined) { - {{ $bracesCoercion += '}'; }} - {{?}} - - {{? it.opts.coerceTypes == 'array' && $type != 'array' }} - if ({{=$dataType}} == 'array' && {{=$data}}.length == 1) { - {{=$coerced}} = {{=$data}} = {{=$data}}[0]; - {{=$dataType}} = typeof {{=$data}}; - /*if ({{=$dataType}} == 'object' && Array.isArray({{=$data}})) {{=$dataType}} = 'array';*/ - } - {{?}} + {{? it.opts.coerceTypes == 'array' }} + if ({{=$dataType}} == 'object' && Array.isArray({{=$data}}) && {{=$data}}.length == 1) { + {{=$data}} = {{=$data}}[0]; + {{=$dataType}} = typeof {{=$data}}; + if ({{=it.util.checkDataType(it.schema.type, $data, it.opts.strictNumbers)}}) {{=$coerced}} = {{=$data}}; + } + {{?}} + if ({{=$coerced}} !== undefined) ; + {{~ $coerceToTypes:$type:$i }} {{? $type == 'string' }} - if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean') + else if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean') {{=$coerced}} = '' + {{=$data}}; else if ({{=$data}} === null) {{=$coerced}} = ''; {{?? $type == 'number' || $type == 'integer' }} - if ({{=$dataType}} == 'boolean' || {{=$data}} === null + else if ({{=$dataType}} == 'boolean' || {{=$data}} === null || ({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}} {{? $type == 'integer' }} && !({{=$data}} % 1){{?}})) {{=$coerced}} = +{{=$data}}; {{?? $type == 'boolean' }} - if ({{=$data}} === 'false' || {{=$data}} === 0 || {{=$data}} === null) + else if ({{=$data}} === 'false' || {{=$data}} === 0 || {{=$data}} === null) {{=$coerced}} = false; else if ({{=$data}} === 'true' || {{=$data}} === 1) {{=$coerced}} = true; {{?? $type == 'null' }} - if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false) + else if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false) {{=$coerced}} = null; {{?? it.opts.coerceTypes == 'array' && $type == 'array' }} - if ({{=$dataType}} == 'string' || {{=$dataType}} == 'number' || {{=$dataType}} == 'boolean' || {{=$data}} == null) + else if ({{=$dataType}} == 'string' || {{=$dataType}} == 'number' || {{=$dataType}} == 'boolean' || {{=$data}} == null) {{=$coerced}} = [{{=$data}}]; {{?}} {{~}} - - {{= $bracesCoercion }} - - if ({{=$coerced}} === undefined) { + else { {{# def.error:'type' }} - } else { + } + + if ({{=$coerced}} !== undefined) { {{# def.setParentData }} {{=$data}} = {{=$coerced}}; {{? !$dataLvl }}if ({{=$parentData}} !== undefined){{?}} diff --git a/spec/coercion.spec.js b/spec/coercion.spec.js index 1a8426af1..587671529 100644 --- a/spec/coercion.spec.js +++ b/spec/coercion.spec.js @@ -146,6 +146,7 @@ coercionArrayRules.string.array = [ { from: [123], to: '123' }, { from: [true], to: 'true'}, { from: [null], to: ''}, + { from: [{}], to: undefined }, { from: ['abc', 'def'], to: undefined }, { from: [], to: undefined } ]; @@ -154,30 +155,39 @@ coercionArrayRules.number.array = [ { from: ['1.5'], to: 1.5 }, { from: [true], to: 1 }, { from: [null], to: 0 }, - // { from: ['abc'], to: undefined }, + { from: ['abc'], to: undefined }, + { from: [{}], to: undefined }, ]; coercionArrayRules.integer.array = [ { from: [1], to: 1 }, { from: ['1'], to: 1 }, { from: [true], to: 1 }, - { from: [null], to: 0 } + { from: [null], to: 0 }, + { from: [1.5], to: undefined }, + { from: ['abc'], to: undefined }, + { from: [{}], to: undefined }, ]; coercionArrayRules.boolean.array = [ { from: [true], to: true }, { from: ['true'], to: true }, { from: [1], to: true }, - // { from: ['abc'], to: undefined }, - // { from: [2], to: undefined }, + { from: [null], to: false }, + { from: ['abc'], to: undefined }, + { from: [2], to: undefined }, + { from: [{}], to: undefined }, ]; coercionArrayRules.null.array = [ { from: [null], to: null }, { from: [''], to: null }, { from: [0], to: null }, { from: [false], to: null }, - // {from: [true], to: undefined}, + { from: ['abc'], to: undefined }, + { from: [1], to: undefined }, + { from: [true], to: undefined }, + { from: [{}], to: undefined }, ]; coercionArrayRules.object.array = [ - { from: [{}], to: undefined } + { from: [{}], to: undefined } ]; coercionArrayRules.array = { From b4568b4938b15869adcb3040acc6d09c8fe024b9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 14 Aug 2020 13:31:56 -0400 Subject: [PATCH 117/127] docs: MOSS grant --- README.md | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ce4507fdb..2a34b7a60 100644 --- a/README.md +++ b/README.md @@ -12,29 +12,30 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) -## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin) +## Mozilla MOSS grant and OpenJS Foundation -I will get straight to the point - I need your support to ensure that the development of Ajv continues. +     -I have developed Ajv for 5 years in my free time, but it is not sustainable. I'd appreciate if you consider supporting its further development with donations: -- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it) -- [Ajv Open Collective️](https://opencollective.com/ajv) +Ajv has been awarded a grant from Mozilla’s [Open Source Support (MOSS) program](https://www.mozilla.org/en-US/moss/) in the “Foundational Technology” track! It will sponsor the development of Ajv support of [JSON Schema version 2019-09](https://tools.ietf.org/html/draft-handrews-json-schema-02) and of [JSON Type Definition](https://tools.ietf.org/html/draft-ucarion-json-type-definition-04). + +Ajv also joined [OpenJS Foundation](https://openjsf.org/) – having this support will help ensure the longevity and stability of Ajv for all its users. + +This [blog post](https://www.poberezkin.com/posts/2020-08-14-ajv-json-validator-mozilla-open-source-grant-openjs-foundation.html) has more details. -There are many small and large improvements that are long due, including the support of the next versions of JSON Schema specification, improving website and documentation, and making Ajv more modular and maintainable to address its limitations - what Ajv needs to evolve is much more than what I can contribute in my free time. +I am looking for the long term maintainers of Ajv – working with [ReadySet](https://www.thereadyset.co/), also sponsored by Mozilla, to establish clear guidelines for the role of a "maintainer" and the contribution standards, and to encourage a wider, more inclusive, contribution from the community. -I would also really appreciate any advice you could give on how to raise funds for Ajv development - whether some suitable open-source fund I could apply to or some sponsor I should approach. -Since 2015 Ajv has become widely used, thanks to your help and contributions: +## Please [sponsor Ajv development](https://github.com/sponsors/epoberezkin) -- **90** contributors 🏗 -- **5,000** dependent npm packages ⚙️ -- **7,000** github stars, from GitHub users [all over the world](https://www.google.com/maps/d/u/0/viewer?mid=1MGRV8ciFUGIbO1l0EKFWNJGYE7iSkDxP&ll=-3.81666561775622e-14%2C4.821737100000007&z=2) ⭐️ -- **5,000,000** dependent repositories on GitHub 🚀 -- **120,000,000** npm downloads per month! 💯 +Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant! -I believe it would benefit all Ajv users to help put together the fund that will be used for its further development - it would allow to bring some additional maintainers to the project. +Your continuing support is very important - the funds will be used to develop and maintain Ajv once the next major version is released. -Thank you +Please sponsor Ajv via: +- [GitHub sponsors page](https://github.com/sponsors/epoberezkin) (GitHub will match it) +- [Ajv Open Collective️](https://opencollective.com/ajv) + +Thank you. #### Open Collective sponsors @@ -156,8 +157,6 @@ Performance of different validators by [json-schema-benchmark](https://github.co - [$data reference](#data-reference) to use values from the validated data as values for the schema keywords - [asynchronous validation](#asynchronous-validation) of custom formats and keywords -Currently Ajv is the only validator that passes all the tests from [JSON Schema Test Suite](https://github.com/json-schema/JSON-Schema-Test-Suite) (according to [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark), apart from the test that requires that `1.0` is not an integer that is impossible to satisfy in JavaScript). - ## Install From 161670b1f8728ad129a66b661479f375d773ec80 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 14 Aug 2020 18:39:21 +0100 Subject: [PATCH 118/127] docs: readme links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a34b7a60..3a88820d8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ ## Mozilla MOSS grant and OpenJS Foundation -     +[](https://www.mozilla.org/en-US/moss/)     [](https://openjsf.org/blog/2020/08/14/ajv-joins-openjs-foundation-as-an-incubation-project/) Ajv has been awarded a grant from Mozilla’s [Open Source Support (MOSS) program](https://www.mozilla.org/en-US/moss/) in the “Foundational Technology” track! It will sponsor the development of Ajv support of [JSON Schema version 2019-09](https://tools.ietf.org/html/draft-handrews-json-schema-02) and of [JSON Type Definition](https://tools.ietf.org/html/draft-ucarion-json-type-definition-04). From cf88d1dc22283dffbfbfed472507fc219b3bdbbb Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 15 Aug 2020 08:19:00 +0100 Subject: [PATCH 119/127] 6.12.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2a1c1f8e..7442ecc72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.3", + "version": "6.12.4", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From 7402f98008c85a733c5d3ee48bac3fd3d648b16a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 17 Aug 2020 11:36:58 +0100 Subject: [PATCH 120/127] fix: boolean schemas with strictKeywords option --- lib/dot/definitions.def | 3 ++- lib/dot/validate.jst | 2 +- spec/boolean.spec.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/dot/definitions.def b/lib/dot/definitions.def index db4ea6f32..709cce36d 100644 --- a/lib/dot/definitions.def +++ b/lib/dot/definitions.def @@ -64,7 +64,8 @@ {{## def.nonEmptySchema:_schema: (it.opts.strictKeywords - ? typeof _schema == 'object' && Object.keys(_schema).length > 0 + ? (typeof _schema == 'object' && Object.keys(_schema).length > 0) + || _schema === false : it.util.schemaHasRules(_schema, it.RULES.all)) #}} diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index fd833a535..32087e71c 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -81,7 +81,7 @@ it.baseId = it.baseId || it.rootId; delete it.isTop; - it.dataPathArr = [undefined]; + it.dataPathArr = [""]; if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) { var $defaultMsg = 'default is ignored in the schema root'; diff --git a/spec/boolean.spec.js b/spec/boolean.spec.js index c4c3b3eb1..0f493859c 100644 --- a/spec/boolean.spec.js +++ b/spec/boolean.spec.js @@ -11,7 +11,8 @@ describe('boolean schemas', function() { ajvs = [ new Ajv, new Ajv({allErrors: true}), - new Ajv({inlineRefs: false}) + new Ajv({inlineRefs: false}), + new Ajv({strictKeywords: true}), ]; }); From 236328e6e6842a9f56803b6d045756ff8372b5c0 Mon Sep 17 00:00:00 2001 From: Hodaka Kasama Date: Fri, 21 Aug 2020 09:59:18 +0900 Subject: [PATCH 121/127] add _opts property in Ajv.Ajv --- lib/ajv.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index cc2881b33..f79218237 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -137,6 +137,7 @@ declare namespace ajv { */ errorsText(errors?: Array | null, options?: ErrorsTextOptions): string; errors?: Array | null; + _opts: any; } interface CustomLogger { From 996333166f991380d4e2d95bc147d0e6e7a33fb6 Mon Sep 17 00:00:00 2001 From: Hodaka Kasama Date: Mon, 7 Sep 2020 17:04:41 +0900 Subject: [PATCH 122/127] change _opts type to Options. --- lib/ajv.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajv.d.ts b/lib/ajv.d.ts index f79218237..078364d8c 100644 --- a/lib/ajv.d.ts +++ b/lib/ajv.d.ts @@ -137,7 +137,7 @@ declare namespace ajv { */ errorsText(errors?: Array | null, options?: ErrorsTextOptions): string; errors?: Array | null; - _opts: any; + _opts: Options; } interface CustomLogger { From f1c8e45b9cdff918be28becf03bf0b339321c398 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 13 Sep 2020 14:12:44 +0100 Subject: [PATCH 123/127] 6.12.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7442ecc72..d764f6860 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.4", + "version": "6.12.5", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts", From 9cd93a1bdbdefd5a7ba3db5e123d20c84d1d1d0e Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Wed, 23 Sep 2020 20:40:38 +0100 Subject: [PATCH 124/127] docs: note about v7 in readme --- README.md | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3a88820d8..1944b851f 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,39 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ [![Build Status](https://travis-ci.org/ajv-validator/ajv.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv) [![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv) +[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv/v/7.0.0-beta.0) [![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv) [![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master) [![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) [![GitHub Sponsors](https://img.shields.io/badge/$-sponsors-brightgreen)](https://github.com/sponsors/epoberezkin) +## Ajv v7 beta is released + +[Ajv version 7.0.0-beta.0](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) is released with these changes: + +- to reduce the mistakes in JSON schemas and unexpected validation results, [strict mode](./docs/strict-mode.md) is added - it prohibits ignored or ambiguous JSON Schema elements. +- to make code injection from untrusted schemas impossible, [code generation](./docs/codegen.md) is fully re-written to be safe. +- to simplify Ajv extensions, the new keyword API that is used by pre-defined keywords is available to user-defined keywords - it is much easier to define any keywords now, especially with subschemas. +- schemas are compiled to ES6 code (ES5 code generation is supported with an option). +- to improve reliability and maintainability the code is migrated to TypeScript. + +**Please note**: + +- the support for JSON-Schema draft-04 is removed - if you have schemas using "id" attributes you have to replace them with "\$id" (or continue using version 6 that will be supported until 02/28/2021). +- all formats are separated to ajv-formats package - they have to be explicitely added if you use them. + +See [release notes](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) for the details. + +To install the new version: + +```bash +npm install ajv@beta +``` + +See [Getting started with v7](https://github.com/ajv-validator/ajv/tree/v7-beta#usage) for code example. + + ## Mozilla MOSS grant and OpenJS Foundation [](https://www.mozilla.org/en-US/moss/)     [](https://openjsf.org/blog/2020/08/14/ajv-joins-openjs-foundation-as-an-incubation-project/) @@ -1449,16 +1476,9 @@ Please see [Contributing guidelines](https://github.com/ajv-validator/ajv/blob/m See https://github.com/ajv-validator/ajv/releases -__Please note__: [Changes in version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0). - -[Version 5.0.0](https://github.com/ajv-validator/ajv/releases/tag/5.0.0). - -[Version 4.0.0](https://github.com/ajv-validator/ajv/releases/tag/4.0.0). - -[Version 3.0.0](https://github.com/ajv-validator/ajv/releases/tag/3.0.0). - -[Version 2.0.0](https://github.com/ajv-validator/ajv/releases/tag/2.0.0). +__Please note__: [Changes in version 7.0.0-beta](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) +[Version 6.0.0](https://github.com/ajv-validator/ajv/releases/tag/v6.0.0). ## Code of conduct From 490e34c4846064db5c962a77087e17078954c2f6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 24 Sep 2020 08:48:14 +0100 Subject: [PATCH 125/127] docs: link to v7-beta branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1944b851f..5aa2078d8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The fastest JSON Schema validator for Node.js and browser. Supports draft-04/06/ ## Ajv v7 beta is released -[Ajv version 7.0.0-beta.0](https://github.com/ajv-validator/ajv/releases/tag/v7.0.0-beta.0) is released with these changes: +[Ajv version 7.0.0-beta.0](https://github.com/ajv-validator/ajv/tree/v7-beta) is released with these changes: - to reduce the mistakes in JSON schemas and unexpected validation results, [strict mode](./docs/strict-mode.md) is added - it prohibits ignored or ambiguous JSON Schema elements. - to make code injection from untrusted schemas impossible, [code generation](./docs/codegen.md) is fully re-written to be safe. From fd363896a8d6c5697b5da41f4d9a400a84efaf8e Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 9 Oct 2020 08:45:27 +0100 Subject: [PATCH 126/127] fix: regular expression for "url" format --- lib/compile/formats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile/formats.js b/lib/compile/formats.js index 7726ee326..de94a63bb 100644 --- a/lib/compile/formats.js +++ b/lib/compile/formats.js @@ -13,8 +13,8 @@ var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@| // For the source: https://gist.github.com/dperini/729294 // For test cases: https://mathiasbynens.be/demo/url-regex // @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983. -// var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu; -var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-?)*(?:[0-9KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[KSa-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i; +// var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu; +var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i; var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i; var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/; var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i; From fe591439f34e24030f69df9eb8d91e6d037a3af7 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 10 Oct 2020 17:09:37 +0100 Subject: [PATCH 127/127] 6.12.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d764f6860..559a933c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "6.12.5", + "version": "6.12.6", "description": "Another JSON Schema Validator", "main": "lib/ajv.js", "typings": "lib/ajv.d.ts",