Skip to content

Commit e37d621

Browse files
fix(MCOL-5842): Fix JSON_OBJECT's handling of empty strings
JSON_OBJECT() (and probably some other JSON functions) now properly handle empty strings in their arguments - JSON_OBJECT used to return NULL, now it returns empty string.
1 parent b6707dd commit e37d621

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
DROP DATABASE IF EXISTS MCOL5842;
2+
CREATE DATABASE MCOL5842;
3+
USE MCOL5842;
4+
CREATE TABLE tcs(t TEXT) ENGINE=Columnstore;
5+
INSERT INTO tcs(t) VALUES ('');
6+
SELECT JSON_OBJECT('t', t, 'a', 'b') FROM tcs;
7+
JSON_OBJECT('t', t, 'a', 'b')
8+
{"t": "", "a": "b"}
9+
SELECT GROUP_CONCAT(JSON_OBJECT('t', t, 'a', 'b')) FROM tcs;
10+
GROUP_CONCAT(JSON_OBJECT('t', t, 'a', 'b'))
11+
{"t": "", "a": "b"}
12+
DROP DATABASE MCOL5842;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--disable_warnings
2+
DROP DATABASE IF EXISTS MCOL5842;
3+
--enable_warnings
4+
CREATE DATABASE MCOL5842;
5+
USE MCOL5842;
6+
7+
CREATE TABLE tcs(t TEXT) ENGINE=Columnstore;
8+
INSERT INTO tcs(t) VALUES ('');
9+
SELECT JSON_OBJECT('t', t, 'a', 'b') FROM tcs;
10+
SELECT GROUP_CONCAT(JSON_OBJECT('t', t, 'a', 'b')) FROM tcs;
11+
12+
DROP DATABASE MCOL5842;

utils/funcexp/jsonhelpers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool appendEscapedJS(string& ret, const CHARSET_INFO* retCS, const utils::NullSt
3232
int strLen = jsLen * 12 * jsCS->mbmaxlen / jsCS->mbminlen;
3333
char* buf = (char*)alloca(strLen);
3434
if ((strLen = json_escape(retCS, (const uchar*)rawJS, (const uchar*)rawJS + jsLen, jsCS, (uchar*)buf,
35-
(uchar*)buf + strLen)) > 0)
35+
(uchar*)buf + strLen)) >= 0)
3636
{
3737
buf[strLen] = '\0';
3838
ret.append(buf, strLen);

0 commit comments

Comments
 (0)