From ed46fdefb169f5360f80bcd28c4fcc1e04617589 Mon Sep 17 00:00:00 2001 From: andrejlevkovitch Date: Fri, 26 Jan 2024 16:39:47 +0100 Subject: [PATCH] fix issue-311 --- src/json-validator.cpp | 6 +++--- test/issue-311/CMakeLists.txt | 3 +++ test/issue-311/instance.json | 3 +++ test/issue-311/schema.json | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/issue-311/CMakeLists.txt create mode 100644 test/issue-311/instance.json create mode 100644 test/issue-311/schema.json diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 1a801bd..4b01217 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -192,10 +192,10 @@ class root_schema // for each token create an object, if not already existing auto unk_kw = &file.unknown_keywords; for (auto &rt : ref_tokens) { - auto existing_object = unk_kw->find(rt); - if (existing_object == unk_kw->end()) + json::json_pointer rt_ptr{"/" + rt}; + if (unk_kw->contains(rt_ptr) == false) (*unk_kw)[rt] = json::object(); - unk_kw = &(*unk_kw)[rt]; + unk_kw = &(*unk_kw)[rt_ptr]; } (*unk_kw)[key] = value; } diff --git a/test/issue-311/CMakeLists.txt b/test/issue-311/CMakeLists.txt new file mode 100644 index 0000000..19b5b8c --- /dev/null +++ b/test/issue-311/CMakeLists.txt @@ -0,0 +1,3 @@ +add_test_simple_schema(Issue::311 + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) diff --git a/test/issue-311/instance.json b/test/issue-311/instance.json new file mode 100644 index 0000000..e571d98 --- /dev/null +++ b/test/issue-311/instance.json @@ -0,0 +1,3 @@ +{ + "element": [1] +} diff --git a/test/issue-311/schema.json b/test/issue-311/schema.json new file mode 100644 index 0000000..3be1b40 --- /dev/null +++ b/test/issue-311/schema.json @@ -0,0 +1,19 @@ +{ + "type": "object", + "properties": { + "element": { + "$ref": "#/$defs/element" + } + }, + "$defs": { + "element": { + "type": "array", + "items": [ + { + "$comment": "the comment should not lead to fail of loading schema", + "type": "number" + } + ] + } + } +}