summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeijun Huang <huangweijun1001@gmail.com>2023-02-12 18:42:23 +0100
committerDaniel Black <daniel@mariadb.org>2023-02-14 11:55:11 +1100
commitbadf6de1715bbdddcaf8c1535747f94602aaa13f (patch)
tree701b6321c41b183a1c5253521503129027d5c288
parentc41c79650aa2ef8eaf3f887b94db8cc7478eadd1 (diff)
downloadmariadb-git-badf6de1715bbdddcaf8c1535747f94602aaa13f.tar.gz
MDEV-30412: JSON_OBJECTAGG doesn't escape double quote in key
-rw-r--r--mysql-test/main/func_json.result12
-rw-r--r--mysql-test/main/func_json.test8
-rw-r--r--sql/item_jsonfunc.cc2
3 files changed, 21 insertions, 1 deletions
diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result
index 2a293fc72c7..b9df193d3bd 100644
--- a/mysql-test/main/func_json.result
+++ b/mysql-test/main/func_json.result
@@ -1623,5 +1623,17 @@ id doc
{"$oid":"611c0a463b150154132f6636"} { "_id" : { "$oid" : "611c0a463b150154132f6636" }, "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : 1.0 } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }
DROP TABLE arrNestTest;
#
+# MDEV-30412 JSON_OBJECTAGG doesn't escape double quote in key
+#
+SELECT JSON_OBJECTAGG('"', 1);
+JSON_OBJECTAGG('"', 1)
+{"\"":1}
+SELECT JSON_OBJECTAGG('\"', 1);
+JSON_OBJECTAGG('\"', 1)
+{"\"":1}
+SELECT JSON_OBJECTAGG('\\', 1);
+JSON_OBJECTAGG('\\', 1)
+{"\\":1}
+#
# End of 10.5 tests
#
diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test
index 35645bcb226..0a5d1638717 100644
--- a/mysql-test/main/func_json.test
+++ b/mysql-test/main/func_json.test
@@ -1068,6 +1068,14 @@ SELECT * FROM arrNestTest;
DROP TABLE arrNestTest;
--echo #
+--echo # MDEV-30412 JSON_OBJECTAGG doesn't escape double quote in key
+--echo #
+
+SELECT JSON_OBJECTAGG('"', 1);
+SELECT JSON_OBJECTAGG('\"', 1);
+SELECT JSON_OBJECTAGG('\\', 1);
+
+--echo #
--echo # End of 10.5 tests
--echo #
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index 9843b6d14b1..b85adeff05d 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -4060,7 +4060,7 @@ bool Item_func_json_objectagg::add()
result.append(", ");
result.append("\"");
- result.append(*key);
+ st_append_escaped(&result,key);
result.append("\":");
buf.length(0);