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

JSON_EXTRACT fails with some escaped unicode as key

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Done
    • 10.2.5
    • 10.2.8
    • JSON
    • Ubuntu 17.04

    Description

      JSON_EXTRACT fails to handle specific escaped unicode sequence. Here is a example:

      SET @str = "{\"\\u00e4\\u00f6\":\"yes\"}";
      SET @path = "$.\"\\u00e4\\u00f6\"";
      select @str, @path, JSON_EXTRACT(@str, @path);
      

      Here JSON extract returns null. I've testet the same code on mysql and it works fine. The next example, containing only the first unicode character runs fine on mariadb and mysql.

      SET @str = "{\"\\u00e4\":\"yes\"}";
      SET @path = "$.\"\\u00e4\"";
      select @str, @path, JSON_EXTRACT(@str, @path);
      

      Attachments

        Activity

          apreiml Armin Preiml created issue -
          elenst Elena Stepanova made changes -
          Field Original Value New Value
          Status Open [ 1 ] Confirmed [ 10101 ]

          MariaDB 10.2

          MariaDB [(none)]> select @str, @path, JSON_EXTRACT(@str, @path);
          +------------------------+------------------+---------------------------+
          | @str                   | @path            | JSON_EXTRACT(@str, @path) |
          +------------------------+------------------+---------------------------+
          | {"\u00e4\u00f6":"yes"} | $."\u00e4\u00f6" | NULL                      |
          +------------------------+------------------+---------------------------+
          1 row in set, 1 warning (0.00 sec)
           
          MariaDB [(none)]> SHOW WARNINGS;
          +---------+------+-----------------------------------------------------------------------------------+
          | Level   | Code | Message                                                                           |
          +---------+------+-----------------------------------------------------------------------------------+
          | Warning | 4042 | Syntax error in JSON path in argument 2 to function 'json_extract' at position 14 |
          +---------+------+-----------------------------------------------------------------------------------+
          1 row in set (0.00 sec)
           
          MariaDB [(none)]> SELECT JSON_VALID(@str);
          +------------------+
          | JSON_VALID(@str) |
          +------------------+
          |                0 |
          +------------------+
          1 row in set (0.00 sec)
          

          MySQL 5.7

          MySQL [test]> select @str, @path, JSON_EXTRACT(@str, @path);
          +------------------------+------------------+---------------------------+
          | @str                   | @path            | JSON_EXTRACT(@str, @path) |
          +------------------------+------------------+---------------------------+
          | {"\u00e4\u00f6":"yes"} | $."\u00e4\u00f6" | "yes"                     |
          +------------------------+------------------+---------------------------+
          1 row in set (0.00 sec)
           
          MySQL [test]> SELECT JSON_VALID(@str);
          +------------------+
          | JSON_VALID(@str) |
          +------------------+
          |                1 |
          +------------------+
          1 row in set (0.00 sec)
          

          elenst Elena Stepanova added a comment - MariaDB 10.2 MariaDB [(none)]> select @str, @path, JSON_EXTRACT(@str, @path); + ------------------------+------------------+---------------------------+ | @str | @path | JSON_EXTRACT(@str, @path) | + ------------------------+------------------+---------------------------+ | { "\u00e4\u00f6" : "yes" } | $. "\u00e4\u00f6" | NULL | + ------------------------+------------------+---------------------------+ 1 row in set , 1 warning (0.00 sec)   MariaDB [(none)]> SHOW WARNINGS; + ---------+------+-----------------------------------------------------------------------------------+ | Level | Code | Message | + ---------+------+-----------------------------------------------------------------------------------+ | Warning | 4042 | Syntax error in JSON path in argument 2 to function 'json_extract' at position 14 | + ---------+------+-----------------------------------------------------------------------------------+ 1 row in set (0.00 sec)   MariaDB [(none)]> SELECT JSON_VALID(@str); + ------------------+ | JSON_VALID(@str) | + ------------------+ | 0 | + ------------------+ 1 row in set (0.00 sec) MySQL 5.7 MySQL [test]> select @str, @path, JSON_EXTRACT(@str, @path); + ------------------------+------------------+---------------------------+ | @str | @path | JSON_EXTRACT(@str, @path) | + ------------------------+------------------+---------------------------+ | { "\u00e4\u00f6" : "yes" } | $. "\u00e4\u00f6" | "yes" | + ------------------------+------------------+---------------------------+ 1 row in set (0.00 sec)   MySQL [test]> SELECT JSON_VALID(@str); + ------------------+ | JSON_VALID(@str) | + ------------------+ | 1 | + ------------------+ 1 row in set (0.00 sec)
          elenst Elena Stepanova made changes -
          Fix Version/s 10.2 [ 14601 ]
          Assignee Alexey Botchkov [ holyfoot ]
          holyfoot Alexey Botchkov made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]

          The bug was fixed by an older commit.

          holyfoot Alexey Botchkov added a comment - The bug was fixed by an older commit.
          holyfoot Alexey Botchkov made changes -
          issue.field.resolutiondate 2017-09-12 13:55:35.0 2017-09-12 13:55:35.695
          holyfoot Alexey Botchkov made changes -
          Fix Version/s 10.2.8 [ 22544 ]
          Fix Version/s 10.2 [ 14601 ]
          Resolution Done [ 10200 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 80712 ] MariaDB v4 [ 152141 ]

          People

            holyfoot Alexey Botchkov
            apreiml Armin Preiml
            Votes:
            1 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.