Skip to content

Commit 4ddcb4e

Browse files
author
Alexey Botchkov
committed
MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
The charset of temporary storage (Item_func_json_insert::tmp_js) was not properly set.
1 parent fc324a5 commit 4ddcb4e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

mysql-test/r/func_json.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,15 @@ select REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC' fro
778778
REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC'
779779
1
780780
drop table t1;
781+
#
782+
# MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
783+
#
784+
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6);
785+
JSON_SET('{}', '$.a', _utf8 0xC3B6)
786+
{"a": "�"}
787+
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6);
788+
JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6)
789+
{"a": "�", "b": "�"}
790+
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6');
791+
JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6')
792+
{"a": "�", "x": 1, "b": "�"}

mysql-test/t/func_json.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,11 @@ select JSON_VALUE(json_col, '$.key1')= _latin1 X'53EC' from t1;
440440
select REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC' from t1;
441441
drop table t1;
442442

443+
--echo #
444+
--echo # MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
445+
--echo #
446+
447+
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6);
448+
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6);
449+
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6');
450+

sql/item_jsonfunc.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,8 +2384,9 @@ String *Item_func_json_insert::val_str(String *str)
23842384
if ((null_value= args[0]->null_value))
23852385
return 0;
23862386

2387-
str->set_charset(js->charset());
2388-
json_string_set_cs(&key_name, js->charset());
2387+
str->set_charset(collation.collation);
2388+
tmp_js.set_charset(collation.collation);
2389+
json_string_set_cs(&key_name, collation.collation);
23892390

23902391
for (n_arg=1, n_path=0; n_arg < arg_count; n_arg+=2, n_path++)
23912392
{
@@ -2599,7 +2600,6 @@ String *Item_func_json_insert::val_str(String *str)
25992600
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
26002601
(const uchar *) js->ptr() + js->length());
26012602
str->length(0);
2602-
str->set_charset(js->charset());
26032603
if (json_nice(&je, str, Item_func_json_format::LOOSE))
26042604
goto js_error;
26052605

0 commit comments

Comments
 (0)