Skip to content

Commit badf6de

Browse files
Weijun-Hgrooverdan
authored andcommitted
MDEV-30412: JSON_OBJECTAGG doesn't escape double quote in key
1 parent c41c796 commit badf6de

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

mysql-test/main/func_json.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,5 +1623,17 @@ id doc
16231623
{"$oid":"611c0a463b150154132f6636"} { "_id" : { "$oid" : "611c0a463b150154132f6636" }, "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : 1.0 } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }
16241624
DROP TABLE arrNestTest;
16251625
#
1626+
# MDEV-30412 JSON_OBJECTAGG doesn't escape double quote in key
1627+
#
1628+
SELECT JSON_OBJECTAGG('"', 1);
1629+
JSON_OBJECTAGG('"', 1)
1630+
{"\"":1}
1631+
SELECT JSON_OBJECTAGG('\"', 1);
1632+
JSON_OBJECTAGG('\"', 1)
1633+
{"\"":1}
1634+
SELECT JSON_OBJECTAGG('\\', 1);
1635+
JSON_OBJECTAGG('\\', 1)
1636+
{"\\":1}
1637+
#
16261638
# End of 10.5 tests
16271639
#

mysql-test/main/func_json.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,14 @@ INSERT INTO test.arrNestTest (doc) VALUES ('{ "_id" : { "$oid" : "611c0a463b1501
10671067
SELECT * FROM arrNestTest;
10681068
DROP TABLE arrNestTest;
10691069

1070+
--echo #
1071+
--echo # MDEV-30412 JSON_OBJECTAGG doesn't escape double quote in key
1072+
--echo #
1073+
1074+
SELECT JSON_OBJECTAGG('"', 1);
1075+
SELECT JSON_OBJECTAGG('\"', 1);
1076+
SELECT JSON_OBJECTAGG('\\', 1);
1077+
10701078
--echo #
10711079
--echo # End of 10.5 tests
10721080
--echo #

sql/item_jsonfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@ bool Item_func_json_objectagg::add()
40604060
result.append(", ");
40614061

40624062
result.append("\"");
4063-
result.append(*key);
4063+
st_append_escaped(&result,key);
40644064
result.append("\":");
40654065

40664066
buf.length(0);

0 commit comments

Comments
 (0)