Skip to content

Commit 8022a5f

Browse files
authored
Merge pull request Tencent#1210 from foxtacles/fix-missing-remote-ref-p
add remote ref pointer to schemaMap_
2 parents 67a17cf + 9640209 commit 8022a5f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/rapidjson/schema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ class GenericSchemaDocument {
16731673
if (const SchemaType* sc = remoteDocument->GetSchema(pointer)) {
16741674
if (schema)
16751675
*schema = sc;
1676+
new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(source, const_cast<SchemaType*>(sc), false, allocator_);
16761677
return true;
16771678
}
16781679
}

test/unittest/schematest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,35 @@ TEST(SchemaValidator, Ref_remote) {
20042004
SchemaValidatorType, PointerType);
20052005
}
20062006

2007+
TEST(SchemaValidator, Ref_remote_issue1210) {
2008+
class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
2009+
SchemaDocument** collection;
2010+
public:
2011+
SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { }
2012+
virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) {
2013+
int i = 0;
2014+
while (collection[i] && SchemaDocument::URIType(uri, length) != collection[i]->GetURI()) ++i;
2015+
return collection[i];
2016+
}
2017+
};
2018+
SchemaDocument* collection[] = { 0, 0, 0 };
2019+
SchemaDocumentProvider provider(collection);
2020+
2021+
Document x, y, z;
2022+
x.Parse("{\"properties\":{\"country\":{\"$ref\":\"y.json#/definitions/country_remote\"}},\"type\":\"object\"}");
2023+
y.Parse("{\"definitions\":{\"country_remote\":{\"$ref\":\"z.json#/definitions/country_list\"}}}");
2024+
z.Parse("{\"definitions\":{\"country_list\":{\"enum\":[\"US\"]}}}");
2025+
2026+
SchemaDocument sz(z, "z.json", 6, &provider);
2027+
collection[0] = &sz;
2028+
SchemaDocument sy(y, "y.json", 6, &provider);
2029+
collection[1] = &sy;
2030+
SchemaDocument sx(x, "x.json", 6, &provider);
2031+
2032+
VALIDATE(sx, "{\"country\":\"UK\"}", false);
2033+
VALIDATE(sx, "{\"country\":\"US\"}", true);
2034+
}
2035+
20072036
#ifdef __clang__
20082037
RAPIDJSON_DIAG_POP
20092038
#endif

0 commit comments

Comments
 (0)