From 8a6c345bcc58b1e1e96ac0cddf42ca373fcf13bd Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 23 Mar 2018 23:33:20 +0100 Subject: [PATCH 1/4] add remote ref to schemaMap_ --- include/rapidjson/schema.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index aefdd95..35748cc 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -1673,6 +1673,7 @@ private: if (const SchemaType* sc = remoteDocument->GetSchema(pointer)) { if (schema) *schema = sc; + new (schemaMap_.template Push()) SchemaEntry(source, const_cast(sc), false, allocator_); return true; } } From c8530d022fdc5a72ec15f0e7e7a1f330b1cd8710 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 26 Mar 2018 13:04:35 +0200 Subject: [PATCH 2/4] add test case for remote ref issue --- test/unittest/schematest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index 121d386..951e9ff 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2004,6 +2004,35 @@ TEST(SchemaValidator, Ref_remote) { SchemaValidatorType, PointerType); } +TEST(SchemaValidator, Ref_remote_issue1210) { + class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider { + SchemaDocument** collection; + public: + SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { } + virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { + int i = 0; + while (collection[i] && typename SchemaDocument::URIType(uri, length) != collection[i]->GetURI()) ++i; + return collection[i]; + } + }; + SchemaDocument* collection[] { 0, 0, 0 }; + SchemaDocumentProvider provider(collection); + + Document x, y, z; + x.Parse("{\"properties\":{\"country\":{\"$ref\":\"y.json#/definitions/country_remote\"}},\"type\":\"object\"}"); + y.Parse("{\"definitions\":{\"country_remote\":{\"$ref\":\"z.json#/definitions/country_list\"}}}"); + z.Parse("{\"definitions\":{\"country_list\":{\"enum\":[\"US\"]}}}"); + + SchemaDocument sz(z, "z.json", 6, &provider); + collection[0] = &sz; + SchemaDocument sy(y, "y.json", 6, &provider); + collection[1] = &sy; + SchemaDocument sx(x, "x.json", 6, &provider); + + VALIDATE(sx, "{\"country\":\"UK\"}", false); + VALIDATE(sx, "{\"country\":\"US\"}", true); +} + #ifdef __clang__ RAPIDJSON_DIAG_POP #endif From f8c8c32b42ee9db055f325252d6f6fc57a34fdf5 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 26 Mar 2018 13:16:31 +0200 Subject: [PATCH 3/4] fix C++03 compatibility --- test/unittest/schematest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index 951e9ff..9c78add 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2015,7 +2015,7 @@ TEST(SchemaValidator, Ref_remote_issue1210) { return collection[i]; } }; - SchemaDocument* collection[] { 0, 0, 0 }; + SchemaDocument* collection[] = { 0, 0, 0 }; SchemaDocumentProvider provider(collection); Document x, y, z; From 9640209f789bfd2f670ee7de4bfec92e94048f0e Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 26 Mar 2018 13:29:52 +0200 Subject: [PATCH 4/4] remove superfluous typename --- test/unittest/schematest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index 9c78add..8cf1c68 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2011,7 +2011,7 @@ TEST(SchemaValidator, Ref_remote_issue1210) { SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { } virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { int i = 0; - while (collection[i] && typename SchemaDocument::URIType(uri, length) != collection[i]->GetURI()) ++i; + while (collection[i] && SchemaDocument::URIType(uri, length) != collection[i]->GetURI()) ++i; return collection[i]; } };