From 59d30e8de64a207684e3dcbef2fb53883af7833a Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Fri, 24 Apr 2020 19:15:47 -0700 Subject: [PATCH 1/3] [299] Add tests for invalid use of fragments in "$id" --- tests/draft2019-09/id.json | 107 +++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 tests/draft2019-09/id.json diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json new file mode 100644 index 00000000..da5cd30b --- /dev/null +++ b/tests/draft2019-09/id.json @@ -0,0 +1,107 @@ +[ + { + "description": "Invalid use of fragments in location-independent $id", + "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"}, + "tests": [ + { + "description": "Identifier name", + "data": { + "$ref": "#foo", + "$defs": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name and no ref", + "data": { + "$defs": { + "A": { "$id": "#foo" } + } + }, + "valid": false + }, + { + "description": "Identifier path", + "data": { + "$ref": "#/a/b", + "$defs": { + "A": { + "$id": "#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/bar#foo", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier path with absolute URI", + "data": { + "$ref": "http://localhost:1234/bar#/a/b", + "$defs": { + "A": { + "$id": "http://localhost:1234/bar#/a/b", + "type": "integer" + } + } + }, + "valid": false + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "valid": false + }, + { + "description": "Identifier path with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#/a/b", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#/a/b", + "type": "integer" + } + } + } + } + }, + "valid": false + } + ] + } +] From 9f5484299023261337d1f5286b9df32e53cc94ea Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Wed, 29 Apr 2020 01:05:57 -0700 Subject: [PATCH 2/3] [300] Add tests for valid use of empty fragments in "$id" --- tests/draft2019-09/id.json | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json index da5cd30b..6b6d6865 100644 --- a/tests/draft2019-09/id.json +++ b/tests/draft2019-09/id.json @@ -103,5 +103,46 @@ "valid": false } ] + }, + { + "description": "Valid use of empty fragments in location-independent $id", + "comment": "These are allowed but discouraged", + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Identifier name with absolute URI", + "data": { + "$ref": "http://localhost:1234/bar", + "$defs": { + "A": { + "$id": "http://localhost:1234/bar#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Identifier name with base URI change in subschema", + "data": { + "$id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#/$defs/B", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$id": "#", + "type": "integer" + } + } + } + } + }, + "valid": true + } + ] } ] From af3c37071dae1db4657260ea7a0392ac0a07cc7c Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Mon, 11 May 2020 12:04:14 -0700 Subject: [PATCH 3/3] Add unnormalized $id tests --- tests/draft2019-09/id.json | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/draft2019-09/id.json b/tests/draft2019-09/id.json index 6b6d6865..cd97d596 100644 --- a/tests/draft2019-09/id.json +++ b/tests/draft2019-09/id.json @@ -144,5 +144,63 @@ "valid": true } ] + }, + { + "description": "Unnormalized $ids are allowed but discouraged", + "schema": { + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "tests": [ + { + "description": "Unnormalized identifier", + "data": { + "$ref": "http://localhost:1234/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/foo/bar/../baz", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment", + "data": { + "$ref": "http://localhost:1234/foo/baz", + "$defs": { + "A": { + "$id": "http://localhost:1234/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + }, + { + "description": "Unnormalized identifier with empty fragment and no ref", + "data": { + "$defs": { + "A": { + "$id": "http://localhost:1234/foo/bar/../baz#", + "type": "integer" + } + } + }, + "valid": true + } + ] } ]