Merge pull request #1065 from yurikhan/invalidSchemaPointer
Fix reported violated schema pointer when that schema is remote
This commit is contained in:
commit
03f5de9d7e
@ -349,6 +349,7 @@ public:
|
|||||||
|
|
||||||
Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) :
|
Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) :
|
||||||
allocator_(allocator),
|
allocator_(allocator),
|
||||||
|
pointer_(p),
|
||||||
typeless_(schemaDocument->GetTypeless()),
|
typeless_(schemaDocument->GetTypeless()),
|
||||||
enum_(),
|
enum_(),
|
||||||
enumCount_(),
|
enumCount_(),
|
||||||
@ -597,6 +598,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PointerType& GetPointer() const {
|
||||||
|
return pointer_;
|
||||||
|
}
|
||||||
|
|
||||||
bool BeginValue(Context& context) const {
|
bool BeginValue(Context& context) const {
|
||||||
if (context.inArray) {
|
if (context.inArray) {
|
||||||
if (uniqueItems_)
|
if (uniqueItems_)
|
||||||
@ -1216,6 +1221,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
AllocatorType* allocator_;
|
AllocatorType* allocator_;
|
||||||
|
PointerType pointer_;
|
||||||
const SchemaType* typeless_;
|
const SchemaType* typeless_;
|
||||||
uint64_t* enum_;
|
uint64_t* enum_;
|
||||||
SizeType enumCount_;
|
SizeType enumCount_;
|
||||||
@ -1651,7 +1657,7 @@ public:
|
|||||||
|
|
||||||
//! Gets the JSON pointer pointed to the invalid schema.
|
//! Gets the JSON pointer pointed to the invalid schema.
|
||||||
PointerType GetInvalidSchemaPointer() const {
|
PointerType GetInvalidSchemaPointer() const {
|
||||||
return schemaStack_.Empty() ? PointerType() : schemaDocument_->GetPointer(&CurrentSchema());
|
return schemaStack_.Empty() ? PointerType() : CurrentSchema().GetPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Gets the keyword of invalid schema.
|
//! Gets the keyword of invalid schema.
|
||||||
|
@ -124,14 +124,20 @@ TEST(SchemaValidator, Hasher) {
|
|||||||
|
|
||||||
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer) \
|
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer) \
|
||||||
{\
|
{\
|
||||||
SchemaValidator validator(schema);\
|
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, SchemaValidator, Pointer) \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer,\
|
||||||
|
SchemaValidatorType, PointerType) \
|
||||||
|
{\
|
||||||
|
SchemaValidatorType validator(schema);\
|
||||||
Document d;\
|
Document d;\
|
||||||
/*printf("\n%s\n", json);*/\
|
/*printf("\n%s\n", json);*/\
|
||||||
d.Parse(json);\
|
d.Parse(json);\
|
||||||
EXPECT_FALSE(d.HasParseError());\
|
EXPECT_FALSE(d.HasParseError());\
|
||||||
EXPECT_FALSE(d.Accept(validator));\
|
EXPECT_FALSE(d.Accept(validator));\
|
||||||
EXPECT_FALSE(validator.IsValid());\
|
EXPECT_FALSE(validator.IsValid());\
|
||||||
if (validator.GetInvalidSchemaPointer() != Pointer(invalidSchemaPointer)) {\
|
if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
|
||||||
StringBuffer sb;\
|
StringBuffer sb;\
|
||||||
validator.GetInvalidSchemaPointer().Stringify(sb);\
|
validator.GetInvalidSchemaPointer().Stringify(sb);\
|
||||||
printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
|
printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
|
||||||
@ -142,7 +148,7 @@ TEST(SchemaValidator, Hasher) {
|
|||||||
printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
|
printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
|
||||||
ADD_FAILURE();\
|
ADD_FAILURE();\
|
||||||
}\
|
}\
|
||||||
if (validator.GetInvalidDocumentPointer() != Pointer(invalidDocumentPointer)) {\
|
if (validator.GetInvalidDocumentPointer() != PointerType(invalidDocumentPointer)) {\
|
||||||
StringBuffer sb;\
|
StringBuffer sb;\
|
||||||
validator.GetInvalidDocumentPointer().Stringify(sb);\
|
validator.GetInvalidDocumentPointer().Stringify(sb);\
|
||||||
printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
|
printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
|
||||||
@ -1348,6 +1354,17 @@ TEST(SchemaValidator, Issue1017_allOfHandler) {
|
|||||||
EXPECT_STREQ("{\"cyanArray2\":[],\"blackArray\":[]}", sb.GetString());
|
EXPECT_STREQ("{\"cyanArray2\":[],\"blackArray\":[]}", sb.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(SchemaValidator, Ref_remote) {
|
||||||
|
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
||||||
|
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
||||||
|
Document sd;
|
||||||
|
sd.Parse("{\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}");
|
||||||
|
SchemaDocumentType s(sd, &provider);
|
||||||
|
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
|
||||||
|
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
||||||
|
INVALIDATE_(s, "null", "/integer", "type", "", SchemaValidatorType, PointerType);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
RAPIDJSON_DIAG_POP
|
RAPIDJSON_DIAG_POP
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user