Commit 1f6ada8d authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-13306 JSON_CONTAINS returns wrong value.

        The 'value' state should be saved to be compared against the
        next array item.
parent 08c493c6
...@@ -152,6 +152,9 @@ json_contains('[{"abc":"def", "def":"abc"}]', '["foo","bar"]') ...@@ -152,6 +152,9 @@ json_contains('[{"abc":"def", "def":"abc"}]', '["foo","bar"]')
select json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]'); select json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]');
json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]') json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]')
1 1
select json_contains('[{"a":"b"},{"c":"d"}]','{"c":"d"}');
json_contains('[{"a":"b"},{"c":"d"}]','{"c":"d"}')
1
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]"); select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]");
json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]") json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]")
1 1
......
...@@ -56,6 +56,7 @@ select json_contains('[1, {"a":1}]', '{}'); ...@@ -56,6 +56,7 @@ select json_contains('[1, {"a":1}]', '{}');
select json_contains('[1, {"a":1}]', '{"a":1}'); select json_contains('[1, {"a":1}]', '{"a":1}');
select json_contains('[{"abc":"def", "def":"abc"}]', '["foo","bar"]'); select json_contains('[{"abc":"def", "def":"abc"}]', '["foo","bar"]');
select json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]'); select json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]');
select json_contains('[{"a":"b"},{"c":"d"}]','{"c":"d"}');
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]"); select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]");
select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[10]"); select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[10]");
......
...@@ -1011,6 +1011,8 @@ static int check_contains(json_engine_t *js, json_engine_t *value) ...@@ -1011,6 +1011,8 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
case JSON_VALUE_ARRAY: case JSON_VALUE_ARRAY:
if (value->value_type != JSON_VALUE_ARRAY) if (value->value_type != JSON_VALUE_ARRAY)
{ {
loc_js= *value;
set_js= FALSE;
while (json_scan_next(js) == 0 && js->state != JST_ARRAY_END) while (json_scan_next(js) == 0 && js->state != JST_ARRAY_END)
{ {
int c_level, v_scalar; int c_level, v_scalar;
...@@ -1021,6 +1023,11 @@ static int check_contains(json_engine_t *js, json_engine_t *value) ...@@ -1021,6 +1023,11 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
if (!(v_scalar= json_value_scalar(js))) if (!(v_scalar= json_value_scalar(js)))
c_level= json_get_level(js); c_level= json_get_level(js);
if (set_js)
*value= loc_js;
else
set_js= TRUE;
if (check_contains(js, value)) if (check_contains(js, value))
{ {
if (json_skip_level(js)) if (json_skip_level(js))
......
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