From b62f97cc8d9aae722df196b0aa88f55181bffc9b Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 1 Jul 2022 15:13:39 -0400 Subject: [PATCH 1/2] Add tests for invalid anchors. Closes: #301 Refs: https://json-schema.org/draft/2020-12/json-schema-core.html#name-defining-location-independe --- tests/draft-next/anchor.json | 16 ++++++++++++++++ tests/draft2019-09/anchor.json | 17 +++++++++++++++++ tests/draft2020-12/anchor.json | 17 +++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index 4e8987e0..b7a31a40 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -200,5 +200,21 @@ "valid": false } ] + }, + { + "description": "invalid anchors", + "schema": { "$ref": "https://json-schema.org/draft/next/schema" }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index 4e8987e0..f62ded80 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -200,5 +200,22 @@ "valid": false } ] + }, + { + "description": "invalid anchors", + "comment": "Section 8.2.3", + "schema": { "$ref": "https://json-schema.org/draft/2019-09/schema" }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 4e8987e0..93335e8b 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -200,5 +200,22 @@ "valid": false } ] + }, + { + "description": "invalid anchors", + "comment": "Section 8.2.2", + "schema": { "$ref": "https://json-schema.org/draft/2020-12/schema" }, + "tests": [ + { + "description": "MUST start with a letter (and not #)", + "data": { "$anchor" : "#foo" }, + "valid": false + }, + { + "description": "JSON pointers are not valid", + "data": { "$anchor" : "/a/b" }, + "valid": false + } + ] } ] From 4811789d092cd423535112d2db0c5cbace85f1bd Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 2 Jul 2022 13:05:58 -0400 Subject: [PATCH 2/2] Also add an anchor test with valid prefix (but still invalid). --- tests/draft-next/anchor.json | 5 +++++ tests/draft2019-09/anchor.json | 5 +++++ tests/draft2020-12/anchor.json | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/tests/draft-next/anchor.json b/tests/draft-next/anchor.json index b7a31a40..f0fcf02f 100644 --- a/tests/draft-next/anchor.json +++ b/tests/draft-next/anchor.json @@ -214,6 +214,11 @@ "description": "JSON pointers are not valid", "data": { "$anchor" : "/a/b" }, "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false } ] } diff --git a/tests/draft2019-09/anchor.json b/tests/draft2019-09/anchor.json index f62ded80..4143d1f6 100644 --- a/tests/draft2019-09/anchor.json +++ b/tests/draft2019-09/anchor.json @@ -215,6 +215,11 @@ "description": "JSON pointers are not valid", "data": { "$anchor" : "/a/b" }, "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false } ] } diff --git a/tests/draft2020-12/anchor.json b/tests/draft2020-12/anchor.json index 93335e8b..17e90806 100644 --- a/tests/draft2020-12/anchor.json +++ b/tests/draft2020-12/anchor.json @@ -215,6 +215,11 @@ "description": "JSON pointers are not valid", "data": { "$anchor" : "/a/b" }, "valid": false + }, + { + "description": "invalid with valid beginning", + "data": { "$anchor" : "foo#something" }, + "valid": false } ] }