[MDEV-12947] COLUMN_JSON does not properly encode newlines Created: 2017-05-29  Updated: 2018-05-16  Resolved: 2018-05-16

Status: Closed
Project: MariaDB Server
Component/s: Dynamic Columns
Affects Version/s: 10.1, 10.1.23, 10.2
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Anthony Ryan Assignee: Oleksandr Byelkin
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Linux


Issue Links:
Duplicate
is duplicated by MDEV-7533 COLUMN_JSON() doesn't escape control ... Closed

 Description   

The JSON spec wants all newline characters encoded as "\n", COLUMN_JSON fails to encode newline characters properly.

Minimal test case:

SELECT COLUMN_JSON(COLUMN_CREATE("foo", "New
line" AS CHAR));

Current output:

{"foo":"New
line"}

Expected output:

{"foo":"New\nline"}



 Comments   
Comment by Elena Stepanova [ 2017-06-02 ]

What is the "JSON spec" that you are referring to? Could you please give a link?

Comment by Anthony Ryan [ 2017-06-02 ]

The JSON spec can be found here:

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf

Section 9 describes the correct formatting of a string and lists all characters that need special encoding.

Comment by Elena Stepanova [ 2017-06-02 ]

Thanks.

Since COLUMN_JSON is supposed to take a string as an argument and return a JSON-formatted object, it seems to be a valid point.

Here is an example of a JSON function with string arguments and JSON result in 10.2:

MariaDB [test]> SELECT JSON_OBJECT("foo", "New
line");
+--------------------------------+
| JSON_OBJECT("foo", "New
line") |
+--------------------------------+
| {"foo": "New\nline"}           |
+--------------------------------+
1 row in set (0.00 sec)

COLUMN_JSON should do the same.

Comment by Anthony Ryan [ 2018-05-15 ]

This issue was resolved by the changes made for MDEV-7533 and can be closed.

Generated at Thu Feb 08 08:01:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.