From d55adf7a57be778fdf60363f682b77c2bc51f434 Mon Sep 17 00:00:00 2001 From: Alexei Rousskikh Date: Thu, 1 Mar 2012 11:23:05 -0500 Subject: fixed missed property check when additionalProperties=false Change-Id: I71f53054c5a4a6da2058caa8c93ac813d0977078 Reviewed-by: Chris Craig --- src/qtjsonschema/checkpoints_p.h | 14 +++----------- tests/auto/jsonschema/tst_jsonschema.cpp | 2 ++ 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 strsSchemaProperties(m_checks.keys()); QList 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 }", -- cgit v1.2.3