Commit 95a9078e authored by Rucha Deodhar's avatar Rucha Deodhar

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.
parent e6511a39
This diff is collapsed.
This diff is collapsed.
...@@ -1373,7 +1373,7 @@ static int handle_match(json_engine_t *je, json_path_t *p, ...@@ -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)) (int) (next_step->type & JSON_PATH_KEY_OR_ARRAY))
return json_skip_level(je); return json_skip_level(je);
if (next_step->type == JSON_PATH_ARRAY) if (next_step->type & JSON_PATH_ARRAY)
{ {
int array_size; int array_size;
if (next_step->n_item >= 0) if (next_step->n_item >= 0)
...@@ -1418,6 +1418,7 @@ int json_find_path(json_engine_t *je, ...@@ -1418,6 +1418,7 @@ int json_find_path(json_engine_t *je,
int *array_counters) int *array_counters)
{ {
json_string_t key_name; json_string_t key_name;
int res= 0;
json_string_set_cs(&key_name, p->s.cs); json_string_set_cs(&key_name, p->s.cs);
...@@ -1444,8 +1445,15 @@ int json_find_path(json_engine_t *je, ...@@ -1444,8 +1445,15 @@ int json_find_path(json_engine_t *je,
break; break;
case JST_VALUE: case JST_VALUE:
DBUG_ASSERT(cur_step->type & JSON_PATH_ARRAY); DBUG_ASSERT(cur_step->type & JSON_PATH_ARRAY);
if (cur_step->type & (JSON_PATH_WILD | JSON_PATH_ARRAY_RANGE) || if (cur_step->type & JSON_PATH_ARRAY_RANGE)
cur_step->n_item == array_counters[cur_step - p->steps]++) {
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. */ /* Array item matches. */
if (cur_step == p->last_step || if (cur_step == p->last_step ||
......
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