summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2023-04-04 14:39:41 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2023-04-26 11:00:08 +0530
commit1c25b5c02666420eba5708bb93a6a41e7d7a3a63 (patch)
treec4b3f7774ca8727b081f49924a8ad68fe430a567
parentee41fa38fc3b393e0e7b73bed098274248b8492d (diff)
downloadmariadb-git-1c25b5c02666420eba5708bb93a6a41e7d7a3a63.tar.gz
MDEV-30977: Additional key values are not validating properly when using
unevaluatedProperties with properties declared in subschemas Analysis: When a key fails to validate for "properties" when "properties" is being treated as alternate schema, it needs to fall back on alternate schema for "properites" itself ("unevaluatedProperties" in context of the bug). But that doesn't happen and we end up returning false (=validated) Fix: When "properties" fails to validate as an alternate schema, fall back on alternate schema for "properties" itself.
-rw-r--r--mysql-test/main/func_json.result22
-rw-r--r--mysql-test/main/func_json.test21
-rw-r--r--sql/json_schema.cc9
3 files changed, 52 insertions, 0 deletions
diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result
index 29939d69e83..da8cb3008bf 100644
--- a/mysql-test/main/func_json.result
+++ b/mysql-test/main/func_json.result
@@ -4497,6 +4497,28 @@ SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
ERROR HY000: Invalid value for keyword required
#
+# MDEV-30977: Additional key values are not validating properly when using
+# unevaluatedProperties with properties declared in subschemas
+#
+SET @unevaluatedProperties_schema= '{
+ "allOf": [
+ {
+ "type": "object",
+ "properties": {
+ "name": { "type": "string" }
+ }
+ }
+ ],
+ "properties": {
+ "type": { "enum": ["residential", "business"] }
+ },
+ "required": ["type"],
+ "unevaluatedProperties": false
+}';
+SELECT JSON_SCHEMA_VALID(@unevaluatedProperties_schema, '{"name": "joe", "type": "business", "dummy" : "hello" }');
+JSON_SCHEMA_VALID(@unevaluatedProperties_schema, '{"name": "joe", "type": "business", "dummy" : "hello" }')
+0
+#
# MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
#
SET @schema_pattern='{
diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test
index 5517dcfa6c8..4a400f1de90 100644
--- a/mysql-test/main/func_json.test
+++ b/mysql-test/main/func_json.test
@@ -3398,6 +3398,27 @@ SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
+--echo #
+--echo # MDEV-30977: Additional key values are not validating properly when using
+--echo # unevaluatedProperties with properties declared in subschemas
+--echo #
+
+SET @unevaluatedProperties_schema= '{
+ "allOf": [
+ {
+ "type": "object",
+ "properties": {
+ "name": { "type": "string" }
+ }
+ }
+ ],
+ "properties": {
+ "type": { "enum": ["residential", "business"] }
+ },
+ "required": ["type"],
+ "unevaluatedProperties": false
+}';
+SELECT JSON_SCHEMA_VALID(@unevaluatedProperties_schema, '{"name": "joe", "type": "business", "dummy" : "hello" }');
--echo #
--echo # MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
diff --git a/sql/json_schema.cc b/sql/json_schema.cc
index cdfe91a206d..dcfae1d8205 100644
--- a/sql/json_schema.cc
+++ b/sql/json_schema.cc
@@ -1883,6 +1883,13 @@ bool Json_schema_properties::validate_as_alternate(const json_engine_t *je,
return true;
}
}
+ else
+ {
+ if (alternate_schema && alternate_schema->validate_as_alternate(je, k_start, k_end))
+ {
+ return true;
+ }
+ }
return false;
}
@@ -1892,6 +1899,8 @@ Json_schema_additional_and_unevaluated::
const uchar* k_start,
const uchar* k_end)
{
+ if (!allowed)
+ return true;
return validate_schema_items(je, &schema_list);
}