Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2.10
    • 10.2.11
    • JSON
    • None
    • Using official mariadb docker image

    Description

      Based on official example :

      SET @json='{ "x": [0,1], "y": "[0,1]", "z": "Mon\\\"t\\\"y" }';
      SELECT @json, JSON_VALUE(@json,'$.z');
      

      return :

      @json                                           JSON_VALUE(@json,'$.z')  
      ----------------------------------------------  -------------------------
      { "x": [0,1], "y": "[0,1]", "z": "Mon\"t\"y" }  Mon\"t\"y                
      

      as you can see Mon\"t\"y is not escape as it must be

      Attachments

        Activity

          alice Alice Sherepa added a comment -

          It works as expected. According to https://mariadb.com/kb/en/library/differences-between-json_query-and-json_value/
          JSON_VALUE shoud return string literal from "Mon\\\"t\\\"y"

          MariaDB [test]> select "Mon\\\"t\\\"y";
          +-----------+
          | Mon\"t\"y |
          +-----------+
          | Mon\"t\"y |
          +-----------+
          1 row in set (0.00 sec)
          

          After rules about string literals https://mariadb.com/kb/en/library/string-literals/

          "Mon\\\"t\\\"y" -> Mon\(\\)\"t\\\"y -> Mon\"(\")t\\\"y -> Mon\"t\(\\)\"y  -> Mon\"t\"(\")y -> Mon\"t\"y
          

          alice Alice Sherepa added a comment - It works as expected. According to https://mariadb.com/kb/en/library/differences-between-json_query-and-json_value/ JSON_VALUE shoud return string literal from "Mon\\\"t\\\"y" MariaDB [test]> select "Mon\\\"t\\\"y" ; + -----------+ | Mon\"t\"y | + -----------+ | Mon\"t\"y | + -----------+ 1 row in set (0.00 sec) After rules about string literals https://mariadb.com/kb/en/library/string-literals/ "Mon\\\"t\\\"y" -> Mon\(\\)\"t\\\"y -> Mon\"(\")t\\\"y -> Mon\"t\(\\)\"y -> Mon\"t\"(\")y -> Mon\"t\"y
          tchiot.ludo Lu Do added a comment -

          I think you don't understand the bug.
          Let me explain it more :

          CREATE TABLE `test`.`test`( `test` TEXT ); 
          INSERT INTO test (test) VALUES ('{ "x": [0,1], "y": "[0,1]", "z": "Mon\\\"t\\\"y" }');
          SELECT * FROM test ;
          

          test                                            
          ------------------------------------------------
          { "x": [0,1], "y": "[0,1]", "z": "Mon\"t\"y" }  
          

          As you can see the \" \" is escape needed by Json to be a valid json.

          But when I extract a value the escaped is not needed and must be remove to have the valid string.

          SELECT JSON_VALUE(@json,'$.z') FROM test;
          

          JSON_VALUE(@json,'$.z')  
          -------------------------
          Mon\"t\"y                
          

          In my case, I insert a value Mon"t"y and I expect to extract the same value not an escape one Mon\"t\"y

          Another example :

          TRUNCATE TABLE test;
          INSERT INTO test (test) VALUES ('[0]');
          UPDATE test SET test=JSON_ARRAY_APPEND(test, '$', "Mon\"t\"y")
          SELECT "Mon\"t\"y", JSON_VALUE(test, '$[1]'), JSON_EXTRACT(test, '$[1]') FROM test
          

          Mon"t"y  JSON_VALUE(test, '$[1]')  JSON_EXTRACT(test, '$[1]')  
          -------  ------------------------  ----------------------------
          Mon"t"y  Mon\"t\"y                 "Mon\"t\"y"                 
          

          As you can see I append to the array : Mon"t"y and when I query with JSON_VALUE I have : Mon\"t\"y
          Still the escape is not wanted with JSON_VALUE

          with JSON_EXTRACT, my software can do json_decode for example and will received the right value.
          with JSON_VALUE, my software can't do json_decode since it's not a json value, and I don't have the right value

          tchiot.ludo Lu Do added a comment - I think you don't understand the bug. Let me explain it more : CREATE TABLE `test`.`test`( `test` TEXT ); INSERT INTO test (test) VALUES ( '{ "x": [0,1], "y": "[0,1]", "z": "Mon\\\"t\\\"y" }' ); SELECT * FROM test ; test ------------------------------------------------ { "x": [0,1], "y": "[0,1]", "z": "Mon\"t\"y" } As you can see the \" \" is escape needed by Json to be a valid json. But when I extract a value the escaped is not needed and must be remove to have the valid string. SELECT JSON_VALUE(@json, '$.z' ) FROM test; JSON_VALUE(@json,'$.z') ------------------------- Mon\"t\"y In my case, I insert a value Mon"t"y and I expect to extract the same value not an escape one Mon\"t\"y Another example : TRUNCATE TABLE test; INSERT INTO test (test) VALUES ( '[0]' ); UPDATE test SET test=JSON_ARRAY_APPEND(test, '$' , "Mon\"t\"y" ) SELECT "Mon\"t\"y" , JSON_VALUE(test, '$[1]' ), JSON_EXTRACT(test, '$[1]' ) FROM test Mon"t"y JSON_VALUE(test, '$[1]') JSON_EXTRACT(test, '$[1]') ------- ------------------------ ---------------------------- Mon"t"y Mon\"t\"y "Mon\"t\"y" As you can see I append to the array : Mon"t"y and when I query with JSON_VALUE I have : Mon\"t\"y Still the escape is not wanted with JSON_VALUE with JSON_EXTRACT, my software can do json_decode for example and will received the right value. with JSON_VALUE, my software can't do json_decode since it's not a json value, and I don't have the right value
          alice Alice Sherepa added a comment -

          yes, I admit I was wrong, JSON_VALUE should probably return Mon"t"y
          I reopen this bug

          alice Alice Sherepa added a comment - yes, I admit I was wrong, JSON_VALUE should probably return Mon"t"y I reopen this bug
          holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2017-November/011666.html

          People

            holyfoot Alexey Botchkov
            tchiot.ludo Lu Do
            Votes:
            0 Vote for this issue
            Watchers:
            5 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.