diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index bd50bc1d6ef23..455efaa6d655b 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -5396,3 +5396,49 @@ result [["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]] [["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]] # End of 11.4 Test +# +# MDEV-38033: JSON_SCHEMA_VALID function returning wrong result +# +SET @schema= ' +{ + "type": "object", + "properties": + { + "id": { + "type": "string", + "minLength": 1 + }, + "arr_fields": { + "type": "array", + "items": { + "type": "object", + "properties": { + "field1": { + "type": "string" + }, + "field2": { + "type": "number" + } + }, + "required": ["field1"] + } + } + } +}'; +SET @value= ' +{ + "id": "zero", + "arr_fields": [ + { + "field1": "A", + "field2": 123 + }, + { + "field1": "B" + } + ] +}'; +SELECT JSON_SCHEMA_VALID(@schema, @value); +JSON_SCHEMA_VALID(@schema, @value) +1 +# End of 12.1 Test diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index 625b832f852cb..ccd140754a346 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -4277,3 +4277,52 @@ SELECT ( WITH x AS ( WITH x ( x ) AS ( SELECT ( 1.000000 ) ) SELECT x FROM x ) S select json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]') as result from mysql.user; --echo # End of 11.4 Test + +--echo # +--echo # MDEV-38033: JSON_SCHEMA_VALID function returning wrong result +--echo # + +SET @schema= ' +{ + "type": "object", + "properties": + { + "id": { + "type": "string", + "minLength": 1 + }, + "arr_fields": { + "type": "array", + "items": { + "type": "object", + "properties": { + "field1": { + "type": "string" + }, + "field2": { + "type": "number" + } + }, + "required": ["field1"] + } + } + } +}'; + +SET @value= ' +{ + "id": "zero", + "arr_fields": [ + { + "field1": "A", + "field2": 123 + }, + { + "field1": "B" + } + ] +}'; + +SELECT JSON_SCHEMA_VALID(@schema, @value); + +--echo # End of 12.1 Test diff --git a/sql/json_schema.cc b/sql/json_schema.cc index 9cbc613d4d95b..a1ef59119a33a 100644 --- a/sql/json_schema.cc +++ b/sql/json_schema.cc @@ -1218,6 +1218,11 @@ bool Json_schema_items::validate(const json_engine_t *je, count++; if (validate_schema_items(&curr_je, &items_schema)) return true; + if (!json_value_scalar(&curr_je)) + { + if (json_skip_level(&curr_je)) + return true; + } } return is_false ? (!count ? false : true) : false;