diff options
-rw-r--r-- | mysql-test/r/func_json.result | 12 | ||||
-rw-r--r-- | mysql-test/t/func_json.test | 11 | ||||
-rw-r--r-- | sql/item_jsonfunc.cc | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 206f745a0d2..2a2df00ff61 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -766,3 +766,15 @@ DROP TABLE t1; select json_array(1,uuid(),compress(5.140264e+307)); json_array(1,uuid(),compress(5.140264e+307)) NULL +# +# MDEV-16869 String functions don't respect character set of JSON_VALUE. +# +create table t1(json_col TEXT) DEFAULT CHARSET=latin1; +insert into t1 values (_latin1 X'7B226B657931223A2253EC227D'); +select JSON_VALUE(json_col, '$.key1')= _latin1 X'53EC' from t1; +JSON_VALUE(json_col, '$.key1')= _latin1 X'53EC' +1 +select REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC' from t1; +REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC' +1 +drop table t1; diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index c2cc00dd6e2..41e520404b6 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -429,3 +429,14 @@ DROP TABLE t1; select json_array(1,uuid(),compress(5.140264e+307)); + +--echo # +--echo # MDEV-16869 String functions don't respect character set of JSON_VALUE. +--echo # + +create table t1(json_col TEXT) DEFAULT CHARSET=latin1; +insert into t1 values (_latin1 X'7B226B657931223A2253EC227D'); +select JSON_VALUE(json_col, '$.key1')= _latin1 X'53EC' from t1; +select REPLACE(JSON_VALUE(json_col, '$.key1'), 'null', '') = _latin1 X'53EC' from t1; +drop table t1; + diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index ac0d7e9e6b0..e9d38b78843 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -479,7 +479,7 @@ String *Item_func_json_value::val_str(String *str) (const uchar *) js->ptr() + js->length()); str->length(0); - str->set_charset(&my_charset_utf8mb4_bin); + str->set_charset(collation.collation); path.cur_step= path.p.steps; continue_search: |