Commit d26b9f67 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11470 JSON_KEYS accepts arguments in invalid format.

        Now JSON functions return warnings if arguments are invalid.
parent 1b7a794b
......@@ -102,6 +102,7 @@ typedef struct st_json_path_t
json_path_step_t *last_step; /* Points to the last step. */
int mode_strict; /* TRUE if the path specified as 'strict' */
enum json_path_step_types types_used; /* The '|' of all step's 'type'-s */
} json_path_t;
......
......@@ -92,7 +92,9 @@ select json_contains('[1]', '[1]', '$', '$[0]');
ERROR 42000: Incorrect parameter count in the call to native function 'json_contains'
select json_contains('', '', '$');
json_contains('', '', '$')
0
NULL
Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_contains'
select json_contains('null', 'null', '$');
json_contains('null', 'null', '$')
1
......@@ -276,6 +278,8 @@ ERROR 42000: Incorrect parameter count in the call to native function 'json_merg
select json_merge('string', 123);
json_merge('string', 123)
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge' at position 1
select json_merge('"string"', 123);
json_merge('"string"', 123)
["string", 123]
......@@ -294,6 +298,8 @@ NULL
select json_merge('a','b');
json_merge('a','b')
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge' at position 1
select json_merge('{"a":"b"}','{"c":"d"}');
json_merge('{"a":"b"}','{"c":"d"}')
{"a":"b", "c":"d"}
......@@ -321,6 +327,11 @@ json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a")
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.b");
json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.b")
NULL
select json_keys('foo');
json_keys('foo')
NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_keys' at position 1
SET @j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
select json_search(@j, 'one', 'abc');
json_search(@j, 'one', 'abc')
......@@ -385,6 +396,8 @@ json_depth('[[[1,2,3],"s"], {}, []]')
select json_length('');
json_length('')
NULL
Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_length'
select json_length('{}');
json_length('{}')
0
......
......@@ -129,6 +129,7 @@ select json_type('123.12');
select json_keys('{"a":{"c":1, "d":2}, "b":2}');
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a");
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.b");
select json_keys('foo');
SET @j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
select json_search(@j, 'one', 'abc');
......
This diff is collapsed.
......@@ -7414,3 +7414,27 @@ ER_BINLOG_NON_SUPPORTED_BULK
eng "Only row based replication supported for bulk operations"
ER_BINLOG_UNCOMPRESS_ERROR
eng "Uncompress the compressed binlog failed"
ER_JSON_BAD_CHR
eng "Broken JSON string in argument %d to function '%s' at position %d"
ER_JSON_NOT_JSON_CHR
eng "Character disallowd in JSON in argument %d to function '%s' at position %d"
ER_JSON_EOS
eng "Unexpected end of JSON text in argument %d to function '%s'"
ER_JSON_SYNTAX
eng "Syntax error in JSON text in argument %d to function '%s' at position %d"
ER_JSON_ESCAPING
eng "Incorrect escaping in JSON text in argument %d to function '%s' at position %d"
ER_JSON_DEPTH
eng "Limit of %d on JSON nested strucures depth is reached in argument %d to function '%s' at position %d"
ER_JSON_PATH_EOS
eng "Unexpected end of JSON path in argument %d to function '%s'"
ER_JSON_PATH_SYNTAX
eng "Syntax error in JSON path in argument %d to function '%s' at position %d"
ER_JSON_PATH_DEPTH
eng "Limit of %d on JSON path depth is reached in argument %d to function '%s' at position %d"
ER_JSON_PATH_NO_WILDCARD
eng "Wildcards in JSON path not allowed in argument %d to function '%s'"
ER_JSON_PATH_ARRAY
eng "JSON path should end with an array identifier in argument %d to function '%s'"
ER_JSON_ONE_OR_ALL
eng "Argument 2 to function '%s' must be "one" or "all"."
......@@ -392,12 +392,12 @@ static int v_string(json_engine_t *j)
static int read_strn(json_engine_t *j)
{
j->value= j->s.c_str;
j->value_type= JSON_VALUE_STRING;
if (skip_str_constant(j))
return 1;
j->state= *j->stack_p;
j->value_type= JSON_VALUE_STRING;
j->value_len= (j->s.c_str - j->value) - 1;
return 0;
}
......@@ -556,9 +556,9 @@ static int skip_string_verbatim(json_string_t *s, const char *str)
s->c_str+= c_len;
continue;
}
return JE_SYN;
return s->error= JE_SYN;
}
return json_eos(s) ? JE_EOS : JE_BAD_CHR;
return s->error= json_eos(s) ? JE_EOS : JE_BAD_CHR;
}
return 0;
......@@ -1078,6 +1078,7 @@ int json_path_setup(json_path_t *p,
p->steps[0].type= JSON_PATH_ARRAY_WILD;
p->last_step= p->steps;
p->mode_strict= FALSE;
p->types_used= JSON_PATH_KEY_NULL;
do
{
......@@ -1109,6 +1110,7 @@ int json_path_setup(json_path_t *p,
if (p->last_step->type & JSON_PATH_DOUBLE_WILD)
return p->s.error= JE_SYN;
p->last_step->type|= JSON_PATH_WILD;
p->types_used|= JSON_PATH_WILD;
continue;
case PS_INT:
p->last_step->n_item*= 10;
......@@ -1122,7 +1124,7 @@ int json_path_setup(json_path_t *p,
p->last_step++;
if (p->last_step - p->steps >= JSON_DEPTH_LIMIT)
return p->s.error= JE_DEPTH;
p->last_step->type= JSON_PATH_KEY | double_wildcard;
p->types_used|= p->last_step->type= JSON_PATH_KEY | double_wildcard;
double_wildcard= JSON_PATH_KEY_NULL;
p->last_step->key= p->s.c_str;
continue;
......@@ -1134,7 +1136,7 @@ int json_path_setup(json_path_t *p,
p->last_step++;
if (p->last_step - p->steps >= JSON_DEPTH_LIMIT)
return p->s.error= JE_DEPTH;
p->last_step->type= JSON_PATH_ARRAY | double_wildcard;
p->types_used|= p->last_step->type= JSON_PATH_ARRAY | double_wildcard;
double_wildcard= JSON_PATH_KEY_NULL;
p->last_step->n_item= 0;
continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment