Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-12947

COLUMN_JSON does not properly encode newlines

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Duplicate
    • 10.1.23, 10.1(EOL), 10.2(EOL)
    • N/A
    • Dynamic Columns
    • None
    • Linux

    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"}
      

      Attachments

        Issue Links

          Activity

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

            elenst Elena Stepanova added a comment - What is the "JSON spec" that you are referring to? Could you please give a link?
            anthonyryan1 Anthony Ryan added a comment - - edited

            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.

            anthonyryan1 Anthony Ryan added a comment - - edited 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.

            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.

            elenst Elena Stepanova added a comment - 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.
            anthonyryan1 Anthony Ryan added a comment -

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

            anthonyryan1 Anthony Ryan added a comment - This issue was resolved by the changes made for MDEV-7533 and can be closed.

            People

              sanja Oleksandr Byelkin
              anthonyryan1 Anthony Ryan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.