revision-id: fc324a5f87827e43f51d1a75e60b3d5abcd807e5 (mariadb-10.2.16-64-gfc324a5) parent(s): affdd79c69dfe443cb9fda06ef156243e1967ac3 committer: Alexey Botchkov timestamp: 2018-08-05 18:33:17 +0400 message: MDEV-16869 String functions don't respect character set of JSON_VALUE. Item_func_json_value::val_str() produced string of wrong charset. --- mysql-test/r/func_json.result | 12 ++++++++++++ mysql-test/t/func_json.test | 11 +++++++++++ sql/item_jsonfunc.cc | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 206f745..2a2df00 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 c2cc00d..41e5204 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 ac0d7e9..e9d38b7 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: