[MDEV-25428] String unexpectedly truncated by JSON_UNQUOTE depending on charset Created: 2021-04-15  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Character Sets, JSON
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6
Fix Version/s: 10.4, 10.5

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Rucha Deodhar
Resolution: Unresolved Votes: 0
Labels: None


 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)


Generated at Thu Feb 08 09:37:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.