Commit f586edd3 authored by Milo Yip's avatar Milo Yip

Fix required for duplicated keys

Fix #608
parent c8a1d517
...@@ -290,6 +290,7 @@ struct SchemaValidationContext { ...@@ -290,6 +290,7 @@ struct SchemaValidationContext {
patternPropertiesSchemaCount(), patternPropertiesSchemaCount(),
valuePatternValidatorType(kPatternValidatorOnly), valuePatternValidatorType(kPatternValidatorOnly),
objectDependencies(), objectDependencies(),
objectRequired(),
inArray(false), inArray(false),
valueUniqueness(false), valueUniqueness(false),
arrayUniqueness(false) arrayUniqueness(false)
...@@ -313,6 +314,8 @@ struct SchemaValidationContext { ...@@ -313,6 +314,8 @@ struct SchemaValidationContext {
factory.FreeState(patternPropertiesSchemas); factory.FreeState(patternPropertiesSchemas);
if (objectDependencies) if (objectDependencies)
factory.FreeState(objectDependencies); factory.FreeState(objectDependencies);
if (objectRequired)
factory.FreeState(objectRequired);
} }
SchemaValidatorFactoryType& factory; SchemaValidatorFactoryType& factory;
...@@ -329,9 +332,9 @@ struct SchemaValidationContext { ...@@ -329,9 +332,9 @@ struct SchemaValidationContext {
SizeType patternPropertiesSchemaCount; SizeType patternPropertiesSchemaCount;
PatternValidatorType valuePatternValidatorType; PatternValidatorType valuePatternValidatorType;
PatternValidatorType objectPatternValidatorType; PatternValidatorType objectPatternValidatorType;
SizeType objectRequiredCount;
SizeType arrayElementIndex; SizeType arrayElementIndex;
bool* objectDependencies; bool* objectDependencies;
bool* objectRequired;
bool inArray; bool inArray;
bool valueUniqueness; bool valueUniqueness;
bool arrayUniqueness; bool arrayUniqueness;
...@@ -365,11 +368,11 @@ public: ...@@ -365,11 +368,11 @@ public:
patternProperties_(), patternProperties_(),
patternPropertyCount_(), patternPropertyCount_(),
propertyCount_(), propertyCount_(),
requiredCount_(),
minProperties_(), minProperties_(),
maxProperties_(SizeType(~0)), maxProperties_(SizeType(~0)),
additionalProperties_(true), additionalProperties_(true),
hasDependencies_(), hasDependencies_(),
hasRequired_(),
hasSchemaDependencies_(), hasSchemaDependencies_(),
additionalItemsSchema_(), additionalItemsSchema_(),
itemsList_(), itemsList_(),
...@@ -490,7 +493,7 @@ public: ...@@ -490,7 +493,7 @@ public:
SizeType index; SizeType index;
if (FindPropertyIndex(*itr, &index)) { if (FindPropertyIndex(*itr, &index)) {
properties_[index].required = true; properties_[index].required = true;
requiredCount_++; hasRequired_ = true;
} }
} }
...@@ -767,7 +770,11 @@ public: ...@@ -767,7 +770,11 @@ public:
if (!(type_ & (1 << kObjectSchemaType))) if (!(type_ & (1 << kObjectSchemaType)))
RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString()); RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
context.objectRequiredCount = 0; if (hasRequired_) {
context.objectRequired = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
std::memset(context.objectRequired, 0, sizeof(bool) * propertyCount_);
}
if (hasDependencies_) { if (hasDependencies_) {
context.objectDependencies = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_)); context.objectDependencies = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
std::memset(context.objectDependencies, 0, sizeof(bool) * propertyCount_); std::memset(context.objectDependencies, 0, sizeof(bool) * propertyCount_);
...@@ -801,8 +808,8 @@ public: ...@@ -801,8 +808,8 @@ public:
else else
context.valueSchema = properties_[index].schema; context.valueSchema = properties_[index].schema;
if (properties_[index].required) if (hasRequired_)
context.objectRequiredCount++; context.objectRequired[index] = true;
if (hasDependencies_) if (hasDependencies_)
context.objectDependencies[index] = true; context.objectDependencies[index] = true;
...@@ -832,8 +839,12 @@ public: ...@@ -832,8 +839,12 @@ public:
} }
bool EndObject(Context& context, SizeType memberCount) const { bool EndObject(Context& context, SizeType memberCount) const {
if (context.objectRequiredCount != requiredCount_) if (hasRequired_)
for (SizeType index = 0; index < propertyCount_; index++) {
if (properties_[index].required)
if (!context.objectRequired[index])
RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString()); RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
}
if (memberCount < minProperties_) if (memberCount < minProperties_)
RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString()); RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
...@@ -1236,11 +1247,11 @@ private: ...@@ -1236,11 +1247,11 @@ private:
PatternProperty* patternProperties_; PatternProperty* patternProperties_;
SizeType patternPropertyCount_; SizeType patternPropertyCount_;
SizeType propertyCount_; SizeType propertyCount_;
SizeType requiredCount_;
SizeType minProperties_; SizeType minProperties_;
SizeType maxProperties_; SizeType maxProperties_;
bool additionalProperties_; bool additionalProperties_;
bool hasDependencies_; bool hasDependencies_;
bool hasRequired_;
bool hasSchemaDependencies_; bool hasSchemaDependencies_;
const SchemaType* additionalItemsSchema_; const SchemaType* additionalItemsSchema_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment