Skip to content
/ server Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 49 additions & 0 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions sql/json_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down