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

String unexpectedly truncated by JSON_UNQUOTE depending on charset

    XMLWordPrintable

    Details

      Description

      This is a query from json_no_table.test. The test runs it with utf8, and it works as it says. However, with latin1 it fails to avoid truncation:

      SET NAMES 'latin1';
      SELECT * FROM (SELECT JSON_UNQUOTE("This is a string that should not be truncated") AS field1) AS DERIVED_TABLE;
      

      10.2 c6d0531c

      MariaDB [test]> SET NAMES 'latin1';
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> SELECT * FROM (SELECT JSON_UNQUOTE("This is a string that should not be truncated") AS field1) AS DERIVED_TABLE;
      +-----------------+
      | field1          |
      +-----------------+
      | This is a strin |
      +-----------------+
      1 row in set (0.000 sec)
       
      MariaDB [test]> SET NAMES utf8;
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [test]> SELECT * FROM (SELECT JSON_UNQUOTE("This is a string that should not be truncated") AS field1) AS DERIVED_TABLE;
      +-----------------------------------------------+
      | field1                                        |
      +-----------------------------------------------+
      | This is a string that should not be truncated |
      +-----------------------------------------------+
      1 row in set (0.001 sec)
      

      Reproducible on 10.2-10.6.

      MySQL returns the full string regardless the character set:

      MySQL 8.0.23

      MySQL [test]> SET NAMES 'latin1';
      Query OK, 0 rows affected (0.000 sec)
       
      MySQL [test]> SELECT * FROM (SELECT JSON_UNQUOTE("This is a string that should not be truncated") AS field1) AS DERIVED_TABLE;
      +-----------------------------------------------+
      | field1                                        |
      +-----------------------------------------------+
      | This is a string that should not be truncated |
      +-----------------------------------------------+
      1 row in set (0.001 sec)
       
      MySQL [test]> SET NAMES utf8;
      Query OK, 0 rows affected, 1 warning (0.000 sec)
       
      MySQL [test]> SELECT * FROM (SELECT JSON_UNQUOTE("This is a string that should not be truncated") AS field1) AS DERIVED_TABLE;
      +-----------------------------------------------+
      | field1                                        |
      +-----------------------------------------------+
      | This is a string that should not be truncated |
      +-----------------------------------------------+
      1 row in set (0.001 sec)
      

        Attachments

          Activity

            People

            Assignee:
            holyfoot Alexey Botchkov
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: