mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-30689: JSON_SCHEMA_VALID for type=array return 1 for any string that
starts with '[' Analysis: When type is non-scalar and the json document has syntax error then it is not detected during validating type. And Since other validate functions take const argument, the error state is not stored eventually. Fix: After we run out of all schemas (in case of no error during validation) from the schema list, go over the json document until there is error in parsing or json doc has ended.
This commit is contained in:
parent
3ef111610b
commit
97675570ca
4 changed files with 69 additions and 1 deletions
|
@ -443,6 +443,11 @@ int json_normalize(DYNAMIC_STRING *result,
|
|||
|
||||
int json_skip_array_and_count(json_engine_t *j, int* n_item);
|
||||
|
||||
inline static int json_scan_ended(json_engine_t *j)
|
||||
{
|
||||
return (j->state == JST_ARRAY_END && j->stack_p == 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -4668,4 +4668,40 @@ JSON_SCHEMA_VALID(@property_names, '{"I_int1":3, "I_ob1":{"key1":"val1"}}')
|
|||
1
|
||||
SET @@sql_mode= @old_sql_mode;
|
||||
set global sql_mode=default;
|
||||
#
|
||||
# MDEV-30287: JSON_SCHEMA_VALID returns incorrect result for type=number
|
||||
#
|
||||
SET @schema= '{"type":"number"}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '3.14');
|
||||
JSON_SCHEMA_VALID(@schema, '3.14')
|
||||
1
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '0zzzz');
|
||||
JSON_SCHEMA_VALID(@schema, '0zzzz')
|
||||
0
|
||||
Warnings:
|
||||
Warning 4038 Syntax error in JSON text in argument 2 to function 'json_schema_valid' at position 2
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '-#');
|
||||
JSON_SCHEMA_VALID(@schema, '-#')
|
||||
0
|
||||
Warnings:
|
||||
Warning 4038 Syntax error in JSON text in argument 2 to function 'json_schema_valid' at position 2
|
||||
#
|
||||
# MDEV-30689: JSON_SCHEMA_VALID for type=array return 1 for any string that starts with '['
|
||||
#
|
||||
SET @schema_array= '{"type":"array"}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema_array, '[');
|
||||
JSON_SCHEMA_VALID(@schema_array, '[')
|
||||
0
|
||||
Warnings:
|
||||
Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_schema_valid'
|
||||
SELECT JSON_SCHEMA_VALID(repeat('[', 100000), json_object());
|
||||
JSON_SCHEMA_VALID(repeat('[', 100000), json_object())
|
||||
NULL
|
||||
Warnings:
|
||||
Warning 4040 Limit of 32 on JSON nested structures depth is reached in argument 1 to function 'json_schema_valid' at position 32
|
||||
SELECT JSON_SCHEMA_VALID(json_object(), repeat('[', 10000000));
|
||||
JSON_SCHEMA_VALID(json_object(), repeat('[', 10000000))
|
||||
0
|
||||
Warnings:
|
||||
Warning 4040 Limit of 32 on JSON nested structures depth is reached in argument 2 to function 'json_schema_valid' at position 32
|
||||
# End of 11.1 test
|
||||
|
|
|
@ -3564,4 +3564,26 @@ SELECT JSON_SCHEMA_VALID(@property_names, '{"I_int1":3, "I_ob1":{"key1":"val1"}}
|
|||
SET @@sql_mode= @old_sql_mode;
|
||||
set global sql_mode=default;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-30287: JSON_SCHEMA_VALID returns incorrect result for type=number
|
||||
--echo #
|
||||
|
||||
SET @schema= '{"type":"number"}';
|
||||
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '3.14');
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '0zzzz');
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '-#');
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-30689: JSON_SCHEMA_VALID for type=array return 1 for any string that starts with '['
|
||||
--echo #
|
||||
|
||||
|
||||
SET @schema_array= '{"type":"array"}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema_array, '[');
|
||||
|
||||
SELECT JSON_SCHEMA_VALID(repeat('[', 100000), json_object());
|
||||
|
||||
SELECT JSON_SCHEMA_VALID(json_object(), repeat('[', 10000000));
|
||||
|
||||
--echo # End of 11.1 test
|
||||
|
|
|
@ -4762,11 +4762,16 @@ longlong Item_func_json_schema_valid::val_int()
|
|||
}
|
||||
}
|
||||
|
||||
if (is_valid && !ve.s.error && !json_scan_ended(&ve))
|
||||
{
|
||||
while (json_scan_next(&ve) == 0) /* no-op */;
|
||||
}
|
||||
|
||||
end:
|
||||
if (unlikely(ve.s.error))
|
||||
{
|
||||
is_valid= 0;
|
||||
report_json_error(val, &ve, 2);
|
||||
report_json_error(val, &ve, 1);
|
||||
}
|
||||
|
||||
return is_valid;
|
||||
|
|
Loading…
Reference in a new issue