MDEV-27412: JSON_TABLE doesn't properly unquote strings
Analysis: The value gets appended as string instead of unescaped json value Fix: Append the value of json in a temporary string and then store it in the field instead of directly storing as string.
This commit is contained in:
parent
6715e4dfe1
commit
753e7d6d7c
@ -1757,5 +1757,14 @@ JSON_INSERT(JSON_OBJECT(l1, l2, l3, l4), '$.k3', 'v3') JSON_SET(JSON_OBJECT(l1,
|
|||||||
{"k1": "v1", "k2": "v2", "k3": "v3"} {"k1": "v1", "k2": "new v2"} {"k1": "v1", "k2": "new v2"}
|
{"k1": "v1", "k2": "v2", "k3": "v3"} {"k1": "v1", "k2": "new v2"} {"k1": "v1", "k2": "new v2"}
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
#
|
#
|
||||||
|
# MDEV-27412: JSON_TABLE doesn't properly unquote strings
|
||||||
|
#
|
||||||
|
SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
|
||||||
|
SELECT
|
||||||
|
data
|
||||||
|
FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
|
||||||
|
data
|
||||||
|
<root language="de"></root>
|
||||||
|
#
|
||||||
# End of 10.6 tests
|
# End of 10.6 tests
|
||||||
#
|
#
|
||||||
|
@ -1189,6 +1189,18 @@ SELECT JSON_ARRAY_APPEND(JSON_ARRAY(l1, l2, l3, l4), '$[0]', 'k3'), JSON_ARRAY_I
|
|||||||
SELECT JSON_INSERT(JSON_OBJECT(l1, l2, l3, l4), '$.k3', 'v3'),JSON_SET(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2'),JSON_REPLACE(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2') from t;
|
SELECT JSON_INSERT(JSON_OBJECT(l1, l2, l3, l4), '$.k3', 'v3'),JSON_SET(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2'),JSON_REPLACE(JSON_OBJECT(l1, l2, l3, l4), '$.k2', 'new v2') from t;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-27412: JSON_TABLE doesn't properly unquote strings
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
|
||||||
|
SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
data
|
||||||
|
FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # End of 10.6 tests
|
--echo # End of 10.6 tests
|
||||||
--echo #
|
--echo #
|
||||||
|
@ -35,6 +35,8 @@ extern "C" /* Bug in BSDI include file */
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
|
extern int st_append_json(String *s,
|
||||||
|
CHARSET_INFO *json_cs, const uchar *js, uint js_len);
|
||||||
class Item_func :public Item_func_or_sum
|
class Item_func :public Item_func_or_sum
|
||||||
{
|
{
|
||||||
void sync_with_sum_func_and_with_field(List<Item> &list);
|
void sync_with_sum_func_and_with_field(List<Item> &list);
|
||||||
|
@ -79,7 +79,7 @@ static inline bool append_simple(String *s, const uchar *a, size_t a_len)
|
|||||||
Appends JSON string to the String object taking charsets in
|
Appends JSON string to the String object taking charsets in
|
||||||
consideration.
|
consideration.
|
||||||
*/
|
*/
|
||||||
static int st_append_json(String *s,
|
int st_append_json(String *s,
|
||||||
CHARSET_INFO *json_cs, const uchar *js, uint js_len)
|
CHARSET_INFO *json_cs, const uchar *js, uint js_len)
|
||||||
{
|
{
|
||||||
int str_len= js_len * s->charset()->mbmaxlen;
|
int str_len= js_len * s->charset()->mbmaxlen;
|
||||||
|
@ -380,6 +380,8 @@ int ha_json_table::rnd_init(bool scan)
|
|||||||
|
|
||||||
static void store_json_in_field(Field *f, const json_engine_t *je)
|
static void store_json_in_field(Field *f, const json_engine_t *je)
|
||||||
{
|
{
|
||||||
|
String res_tmp("", 0, je->s.cs);
|
||||||
|
|
||||||
switch (je->value_type)
|
switch (je->value_type)
|
||||||
{
|
{
|
||||||
case JSON_VALUE_NULL:
|
case JSON_VALUE_NULL:
|
||||||
@ -400,7 +402,8 @@ static void store_json_in_field(Field *f, const json_engine_t *je)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
f->store((const char *) je->value, (uint32) je->value_len, je->s.cs);
|
st_append_json(&res_tmp, je->s.cs, je->value, je->value_len);
|
||||||
|
f->store((const char *) res_tmp.ptr(), (uint32) res_tmp.length(), je->s.cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user