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

JSON_TABLE doesn't properly unquote strings

Details

    Description

      I have trouble with the `JSON_TABLE` function in *MariaDB 10.6.5*. This is my query:

      SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
       
      SELECT
        data
      FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;}}
      

      What I get back is the XML string, but not properly unescaped:

      <root language=\"de\"></root>
      

      When I use then `JSON_VALUE` instead:

      SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
       
      SELECT
        JSON_VALUE(@DATA, '$[0].Data');
      

      then I get back the correctly unescaped string:

      <root language="de"></root>
      

      When I do the same on a MySQL *8.0.26* server, it works as expected:

      SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
       
      SELECT
        data
      FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
       
      -- correct:
      -- <root language="de"></root>
       
      SELECT
        JSON_VALUE(@data, '$[0].Data');
       
      -- correct:
      -- <root language="de"></root>
      

      It looks to me that this difference in behaviour is a bug in MariaDB's side.

      Attachments

        Issue Links

          Activity

            louis77 Louis Brauer created issue -
            louis77 Louis Brauer made changes -
            Field Original Value New Value
            Description I have trouble with the `JSON_TABLE` function in **MariaDB 10.6.5**. This is my query:

            {{SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
            }}
            What I get back is the XML string, but not properly unescaped:

            {{<root language=\"de\"></root>}}

            When I use then `JSON_VALUE` instead:

            {{SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              JSON_VALUE(@DATA, '$[0].Data');}}

            then I get back the correctly unescaped string:

            {{<root language="de"></root>}}

            When I do the same on a MySQL **8.0.26** server, it works as expected:

            {{
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;

            -- correct:
            -- <root language="de"></root>

            SELECT
              JSON_VALUE(@data, '$[0].Data');

            -- correct:
            -- <root language="de"></root>
            }}

            It looks to me that this difference in behaviour is a bug in MariaDB's side.
            I have trouble with the `JSON_TABLE` function in **MariaDB 10.6.5**. This is my query:

            {code:sql}
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;}}
            {code}

            What I get back is the XML string, but not properly unescaped:

            {{<root language=\"de\"></root>}}

            When I use then `JSON_VALUE` instead:

            {{SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              JSON_VALUE(@DATA, '$[0].Data');}}

            then I get back the correctly unescaped string:

            {{<root language="de"></root>}}

            When I do the same on a MySQL **8.0.26** server, it works as expected:

            {{
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;

            -- correct:
            -- <root language="de"></root>

            SELECT
              JSON_VALUE(@data, '$[0].Data');

            -- correct:
            -- <root language="de"></root>
            }}

            It looks to me that this difference in behaviour is a bug in MariaDB's side.
            louis77 Louis Brauer made changes -
            Description I have trouble with the `JSON_TABLE` function in **MariaDB 10.6.5**. This is my query:

            {code:sql}
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;}}
            {code}

            What I get back is the XML string, but not properly unescaped:

            {{<root language=\"de\"></root>}}

            When I use then `JSON_VALUE` instead:

            {{SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              JSON_VALUE(@DATA, '$[0].Data');}}

            then I get back the correctly unescaped string:

            {{<root language="de"></root>}}

            When I do the same on a MySQL **8.0.26** server, it works as expected:

            {{
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;

            -- correct:
            -- <root language="de"></root>

            SELECT
              JSON_VALUE(@data, '$[0].Data');

            -- correct:
            -- <root language="de"></root>
            }}

            It looks to me that this difference in behaviour is a bug in MariaDB's side.
            I have trouble with the `JSON_TABLE` function in **MariaDB 10.6.5**. This is my query:

            {code:sql}
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;}}
            {code}

            What I get back is the XML string, but not properly unescaped:

            {code:xml}
            <root language=\"de\"></root>
            {code}

            When I use then `JSON_VALUE` instead:

            {code:sql}
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              JSON_VALUE(@DATA, '$[0].Data');
            {code}

            then I get back the correctly unescaped string:

            {code:xml}
            <root language="de"></root>
            {code}

            When I do the same on a MySQL **8.0.26** server, it works as expected:

            {code:sql}
            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';

            SELECT
              data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;

            -- correct:
            -- <root language="de"></root>

            SELECT
              JSON_VALUE(@data, '$[0].Data');

            -- correct:
            -- <root language="de"></root>
            {code}

            It looks to me that this difference in behaviour is a bug in MariaDB's side.
            louis77 Louis Brauer made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            Assignee Oleksandr Byelkin [ sanja ]
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Rucha Deodhar [ rucha174 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]

            This issue is a show stopper for our project at the moment. I hope it gets addressed soon.

            BerndLiebermann Bernd Liebermann added a comment - This issue is a show stopper for our project at the moment. I hope it gets addressed soon.
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.7 [ 24805 ]
            greenman Ian Gilfillan made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            rucha174 Rucha Deodhar made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            batonac Kevin Shenk added a comment -

            This is a painful bug. Has anyone found a workaround?

            batonac Kevin Shenk added a comment - This is a painful bug. Has anyone found a workaround?
            batonac Kevin Shenk added a comment - - edited

            I guess the best workaround for now is:

            SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]';
             
            SELECT
              REPLACE(data, "\\", "") as data
            FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
            

            batonac Kevin Shenk added a comment - - edited I guess the best workaround for now is: SET @data = '[{"Data": "<root language=\\"de\\"></root>"}]' ; SELECT REPLACE (data, "\\" , "" ) as data FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data' )) AS t;
            louis77 Louis Brauer added a comment -

            Gosh, two and a half years later this bug is still present in the newest MariaDB release (11.4.2), not even a comment or an ETA.

            I really have a hard time to take MariaDB seriously into consideration for production purposes. Is there anyone at MariaDB who could comment on this issue?

            louis77 Louis Brauer added a comment - Gosh, two and a half years later this bug is still present in the newest MariaDB release (11.4.2), not even a comment or an ETA. I really have a hard time to take MariaDB seriously into consideration for production purposes. Is there anyone at MariaDB who could comment on this issue?
            serg Sergei Golubchik made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            rucha174 Rucha Deodhar added a comment -

            Your frustration is totally understandable and I fully acknowledge the importance of this issue. We're currently working on a fix. Expect an update as soon as we make progress on the completion of this work.

            rucha174 Rucha Deodhar added a comment - Your frustration is totally understandable and I fully acknowledge the importance of this issue. We're currently working on a fix. Expect an update as soon as we make progress on the completion of this work.
            rucha174 Rucha Deodhar made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            rucha174 Rucha Deodhar added a comment - Patch: https://github.com/MariaDB/server/commit/7605ea24e5158c42b83194851d300d42817965c9
            rucha174 Rucha Deodhar made changes -
            Assignee Rucha Deodhar [ rucha174 ] Alexey Botchkov [ holyfoot ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            ok to push.

            holyfoot Alexey Botchkov added a comment - ok to push.
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Rucha Deodhar [ rucha174 ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            rucha174 Rucha Deodhar made changes -
            Fix Version/s 10.6.20 [ 29903 ]
            Fix Version/s 10.6 [ 24028 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            JIraAutomate JiraAutomate made changes -
            Fix Version/s 10.11.10 [ 29904 ]
            Fix Version/s 11.2.6 [ 29906 ]
            Fix Version/s 11.4.4 [ 29907 ]

            People

              rucha174 Rucha Deodhar
              louis77 Louis Brauer
              Votes:
              5 Vote for this issue
              Watchers:
              11 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.