diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2022-03-21 21:19:10 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2022-04-15 01:04:25 +0530 |
commit | 95a9078efcad62daa67e8873802a25ff742890d1 (patch) | |
tree | 942a43d77e43ee421735ddf8eafeb55d0a833056 /strings/json_lib.c | |
parent | e6511a39f8293138a9875b9696b349ced1145590 (diff) | |
download | mariadb-git-95a9078efcad62daa67e8873802a25ff742890d1.tar.gz |
MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for
json path
Analysis: When searching for the given path in json string, if the current
step is of array range type, then path was considered reached which meant
path exists. So output was always true. The end indexes of range were not
evaluated.
Fix: If the current step type for a path is array range, then check if the
value array_counter[] is in range of n_item and n_item_end. If it is, then
path exists. Only then return true. If the range criteria is never met
then return false.
Diffstat (limited to 'strings/json_lib.c')
-rw-r--r-- | strings/json_lib.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/strings/json_lib.c b/strings/json_lib.c index 0b3e7639b5d..ff2421e0eac 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1373,7 +1373,7 @@ static int handle_match(json_engine_t *je, json_path_t *p, (int) (next_step->type & JSON_PATH_KEY_OR_ARRAY)) return json_skip_level(je); - if (next_step->type == JSON_PATH_ARRAY) + if (next_step->type & JSON_PATH_ARRAY) { int array_size; if (next_step->n_item >= 0) @@ -1418,6 +1418,7 @@ int json_find_path(json_engine_t *je, int *array_counters) { json_string_t key_name; + int res= 0; json_string_set_cs(&key_name, p->s.cs); @@ -1444,8 +1445,15 @@ int json_find_path(json_engine_t *je, break; case JST_VALUE: DBUG_ASSERT(cur_step->type & JSON_PATH_ARRAY); - if (cur_step->type & (JSON_PATH_WILD | JSON_PATH_ARRAY_RANGE) || - cur_step->n_item == array_counters[cur_step - p->steps]++) + if (cur_step->type & JSON_PATH_ARRAY_RANGE) + { + res= (cur_step->n_item <= array_counters[cur_step - p->steps] && + cur_step->n_item_end >= array_counters[cur_step - p->steps]); + array_counters[cur_step - p->steps]++; + } + else + res= cur_step->n_item == array_counters[cur_step - p->steps]++; + if ((cur_step->type & JSON_PATH_WILD) || res) { /* Array item matches. */ if (cur_step == p->last_step || |