Commit 0406b2a4 authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-34143: Server crashes when executing JSON_EXTRACT after setting

non-default collation_connection

Analysis:
Due to different collation, the string has nothing to chop off.

Fix:
Got rid of chop(), only append " ," only when we have more elements to
add to the result.
parent ce9efb4e
......@@ -1717,5 +1717,16 @@ SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');
JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D')
{"A": {"B": 1}}
#
# MDEV-34143: Server crashes when executing JSON_EXTRACT after setting non-default collation_connection
#
SET @save_collation_connection= @@collation_connection;
SET collation_connection='utf16_bin';
SELECT JSON_EXTRACT('{"a": 1,"b": 2}','$.a');
JSON_EXTRACT('{"a": 1,"b": 2}','$.a')
NULL
Warnings:
Warning 4036 Character disallowed in JSON in argument 1 to function 'json_extract' at position 2
SET @@collation_connection= @save_collation_connection;
#
# End of 10.5 tests
#
......@@ -1147,6 +1147,18 @@ SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('
SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');
--echo #
--echo # MDEV-34143: Server crashes when executing JSON_EXTRACT after setting non-default collation_connection
--echo #
SET @save_collation_connection= @@collation_connection;
SET collation_connection='utf16_bin';
SELECT JSON_EXTRACT('{"a": 1,"b": 2}','$.a');
SET @@collation_connection= @save_collation_connection;
--echo #
--echo # End of 10.5 tests
--echo #
......@@ -1003,11 +1003,18 @@ String *Item_func_json_extract::read_json(String *str,
je= sav_je;
}
for (int count= 0; count < count_path; count++)
if ((not_first_value && str->append(", ", 2)))
goto error;
while(count_path)
{
if (str->append((const char *) value, v_len) ||
str->append(", ", 2))
goto error; /* Out of memory. */
if (str->append((const char *) value, v_len))
goto error;
count_path--;
if (count_path)
{
if (str->append(", ", 2))
goto error;
}
}
not_first_value= 1;
......@@ -1029,11 +1036,6 @@ String *Item_func_json_extract::read_json(String *str,
goto return_null;
}
if (str->length()>2)
{
str->chop();
str->chop();
}
if (possible_multiple_values && str->append("]", 1))
goto error; /* Out of memory. */
......
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