diff --git a/json/index.js b/json/index.js index 9b8df9360..2684ffe76 100644 --- a/json/index.js +++ b/json/index.js @@ -15,7 +15,10 @@ runTest(4); runTest(6); function runTest(draft) { - var opts = {format: 'full'}; + var opts = { + format: 'full', + formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/} + }; if (draft == 4) opts.meta = false; var ajv = new Ajv(opts); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); diff --git a/json/tests/draft3/additionalProperties.json b/json/tests/draft3/additionalProperties.json index 40831f9e9..90d760734 100644 --- a/json/tests/draft3/additionalProperties.json +++ b/json/tests/draft3/additionalProperties.json @@ -19,10 +19,20 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, diff --git a/json/tests/draft3/dependencies.json b/json/tests/draft3/dependencies.json index 2f6ae489a..d7e09256a 100644 --- a/json/tests/draft3/dependencies.json +++ b/json/tests/draft3/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft3/patternProperties.json b/json/tests/draft3/patternProperties.json index 18586e5da..2ca9aaebd 100644 --- a/json/tests/draft3/patternProperties.json +++ b/json/tests/draft3/patternProperties.json @@ -29,7 +29,12 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft3/properties.json b/json/tests/draft3/properties.json index cd1644dcd..a830c67e7 100644 --- a/json/tests/draft3/properties.json +++ b/json/tests/draft3/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft4/additionalProperties.json b/json/tests/draft4/additionalProperties.json index 40831f9e9..90d760734 100644 --- a/json/tests/draft4/additionalProperties.json +++ b/json/tests/draft4/additionalProperties.json @@ -19,10 +19,20 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, diff --git a/json/tests/draft4/dependencies.json b/json/tests/draft4/dependencies.json index 7b9b16a7e..38effa1a1 100644 --- a/json/tests/draft4/dependencies.json +++ b/json/tests/draft4/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft4/maxProperties.json b/json/tests/draft4/maxProperties.json index d282446ad..513731e4c 100644 --- a/json/tests/draft4/maxProperties.json +++ b/json/tests/draft4/maxProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", "data": "foobar", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft4/minProperties.json b/json/tests/draft4/minProperties.json index a72c7d293..49a0726e0 100644 --- a/json/tests/draft4/minProperties.json +++ b/json/tests/draft4/minProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", "data": "", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft4/patternProperties.json b/json/tests/draft4/patternProperties.json index 18586e5da..5f741dfca 100644 --- a/json/tests/draft4/patternProperties.json +++ b/json/tests/draft4/patternProperties.json @@ -29,7 +29,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft4/properties.json b/json/tests/draft4/properties.json index cd1644dcd..a830c67e7 100644 --- a/json/tests/draft4/properties.json +++ b/json/tests/draft4/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft4/required.json b/json/tests/draft4/required.json index 576ef45ab..1e2a4f0bd 100644 --- a/json/tests/draft4/required.json +++ b/json/tests/draft4/required.json @@ -20,7 +20,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft6/additionalProperties.json b/json/tests/draft6/additionalProperties.json index 40831f9e9..90d760734 100644 --- a/json/tests/draft6/additionalProperties.json +++ b/json/tests/draft6/additionalProperties.json @@ -19,10 +19,20 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, diff --git a/json/tests/draft6/dependencies.json b/json/tests/draft6/dependencies.json index a9b333453..80e552f73 100644 --- a/json/tests/draft6/dependencies.json +++ b/json/tests/draft6/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft6/maxProperties.json b/json/tests/draft6/maxProperties.json index d282446ad..513731e4c 100644 --- a/json/tests/draft6/maxProperties.json +++ b/json/tests/draft6/maxProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", "data": "foobar", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft6/minProperties.json b/json/tests/draft6/minProperties.json index a72c7d293..49a0726e0 100644 --- a/json/tests/draft6/minProperties.json +++ b/json/tests/draft6/minProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", "data": "", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft6/optional/format.json b/json/tests/draft6/optional/format.json index 677891cdc..41f6ac45e 100644 --- a/json/tests/draft6/optional/format.json +++ b/json/tests/draft6/optional/format.json @@ -220,7 +220,7 @@ ] }, { - "description": "validation of JSON-pointers", + "description": "validation of JSON-pointers (JSON String Representation)", "schema": {"format": "json-pointer"}, "tests": [ { @@ -229,29 +229,159 @@ "valid": true }, { - "description": "empty string is valid", + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", "data": "", "valid": true }, { - "description": "/ is valid", + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", "data": "/", "valid": true }, { - "description": "not a valid JSON-pointer (~ not escaped)", - "data": "/foo/bar~", - "valid": false + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true }, { - "description": "valid JSON-pointer with empty segment", - "data": "/foo//bar", + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", "valid": true }, { - "description": "valid JSON-pointer with the last empty segment", - "data": "/foo/bar/", + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false } ] } diff --git a/json/tests/draft6/patternProperties.json b/json/tests/draft6/patternProperties.json index b1f2d3552..1d04a1675 100644 --- a/json/tests/draft6/patternProperties.json +++ b/json/tests/draft6/patternProperties.json @@ -29,7 +29,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": ["foo"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft6/properties.json b/json/tests/draft6/properties.json index d56a96081..c8ad7197f 100644 --- a/json/tests/draft6/properties.json +++ b/json/tests/draft6/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft6/propertyNames.json b/json/tests/draft6/propertyNames.json index 2804b41d3..8423690d9 100644 --- a/json/tests/draft6/propertyNames.json +++ b/json/tests/draft6/propertyNames.json @@ -27,8 +27,18 @@ "valid": true }, { - "description": "non-object is valid", - "data": [], + "description": "ignores arrays", + "data": [1, 2, 3, 4], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft6/required.json b/json/tests/draft6/required.json index 308215713..bd96907b9 100644 --- a/json/tests/draft6/required.json +++ b/json/tests/draft6/required.json @@ -20,7 +20,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true }