summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Rousskikh <ext-alexei.rousskikh@nokia.com>2012-03-01 11:23:05 -0500
committerChris Craig <ext-chris.craig@nokia.com>2012-03-01 18:11:41 +0100
commitd55adf7a57be778fdf60363f682b77c2bc51f434 (patch)
tree0f1a2771ca62f26c4a55b8c6ecb60b5596edad9a
parent49f3d62b76baf32bf324758e5af6ec0b85900eb0 (diff)
fixed missed property check when additionalProperties=false
Change-Id: I71f53054c5a4a6da2058caa8c93ac813d0977078 Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r--src/qtjsonschema/checkpoints_p.h14
-rw-r--r--tests/auto/jsonschema/tst_jsonschema.cpp2
2 files changed, 5 insertions, 11 deletions
diff --git a/src/qtjsonschema/checkpoints_p.h b/src/qtjsonschema/checkpoints_p.h
index 64e21b8..081f895 100644
--- a/src/qtjsonschema/checkpoints_p.h
+++ b/src/qtjsonschema/checkpoints_p.h
@@ -313,21 +313,13 @@ public:
return false;
if (Check::m_data->m_flags.testFlag(CheckSharedData::NoAdditionalProperties)) {
- QList<Key> strsSchemaProperties(m_checks.keys());
QList<Key> strsObjectProperties(object.propertyNames());
- if (strsSchemaProperties.size() == strsObjectProperties.size()) {
- // number of properties are the same but lists still may differ
- qSort(strsSchemaProperties);
- qSort(strsObjectProperties);
- if (!qEqual(strsSchemaProperties.constBegin(), strsSchemaProperties.constEnd(), strsObjectProperties.constBegin())) {
- // lists of properties differ - return an additionalProperties error
+ foreach (const Key &key, strsObjectProperties) {
+ if (!m_checks.contains(key)) {
+ // no additional properties allowed
return false;
}
}
- else {
- // number of properties differ - return an additionalProperties error
- return false;
- }
}
//qDebug() << Q_FUNC_INFO;
diff --git a/tests/auto/jsonschema/tst_jsonschema.cpp b/tests/auto/jsonschema/tst_jsonschema.cpp
index 2a66b26..383284b 100644
--- a/tests/auto/jsonschema/tst_jsonschema.cpp
+++ b/tests/auto/jsonschema/tst_jsonschema.cpp
@@ -203,6 +203,8 @@ void tst_JsonSchema::testAdditionalPropertiesValidation()
"{ \"properties\" : { \"a\" : {}, \"b\" : {} }, \"additionalProperties\" : true }"));
QVERIFY(validate("{ \"a\" : 1, \"b\" : 2, \"c\" : 3 }",
"{ \"properties\" : { \"a\" : {}, \"b\" : {}, \"c\" : {} }, \"additionalProperties\" : false }"));
+ QVERIFY(validate("{ \"a\" : 1, \"b\" : 2 }", // a property 'c' is missing - still valid
+ "{ \"properties\" : { \"a\" : {}, \"b\" : {}, \"c\" : {} }, \"additionalProperties\" : false }"));
QVERIFY(validate("{ \"a\" : 1, \"b\" : 2, \"c\" : 3 }",
"{ \"additionalProperties\" : { \"type\" : \"number\" } }"));
QVERIFY(validate("{ \"a\" : 1, \"b\" : 2, \"c\" : 3 }",