Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSteve Hanson <smh@uk.ibm.com>2021-02-12 20:36:55 +0300
committerSteve Hanson <smh@uk.ibm.com>2021-02-12 20:36:55 +0300
commit9bb81e20ff56f7b3d0c7bb3fcdc8165c9a5df5dc (patch)
treeb3ec6c7c882e39d028f9201b1ce080edd166acbe /test
parent167efb4fa065d3eb1b31699debc89498d04188d8 (diff)
fix crash where simple type with sub-schema has a bad value
Diffstat (limited to 'test')
-rw-r--r--test/unittest/schematest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp
index ad19cd9d..f381b4e9 100644
--- a/test/unittest/schematest.cpp
+++ b/test/unittest/schematest.cpp
@@ -2550,6 +2550,34 @@ TEST(SchemaValidator, ContinueOnErrors_RogueString) {
CrtAllocator::Free(schema);
}
+// Test that when kValidateContinueOnErrorFlag is set, an incorrect simple type with a sub-schema is handled correctly.
+// This tests that we don't blow up when there is a type mismatch but there is a sub-schema present
+TEST(SchemaValidator, ContinueOnErrors_Issue2) {
+ Document sd;
+ sd.Parse("{\"type\":\"string\", \"anyOf\":[{\"maxLength\":2}]}");
+ ASSERT_FALSE(sd.HasParseError());
+ SchemaDocument s(sd);
+ VALIDATE(s, "\"AB\"", true);
+ INVALIDATE_(s, "\"ABC\"", "#", "errors", "#",
+ "{ \"anyOf\": {"
+ " \"errors\": [{"
+ " \"maxLength\": {"
+ " \"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\", \"expected\": 2, \"actual\": \"ABC\""
+ " }"
+ " }],"
+ " \"errorCode\": 24, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
+ " }"
+ "}",
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
+ // Invalid type
+ INVALIDATE_(s, "333", "#", "errors", "#",
+ "{ \"type\": {"
+ " \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"expected\": [\"string\"], \"actual\": \"integer\""
+ " }"
+ "}",
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
+}
+
TEST(SchemaValidator, Schema_UnknownError) {
ASSERT_TRUE(SchemaValidator::SchemaType::GetValidateErrorKeyword(kValidateErrors).GetString() == std::string("null"));
}