[MDEV-12774] JSON_EXTRACT fails with some escaped unicode as key Created: 2017-05-10  Updated: 2017-09-12  Resolved: 2017-09-12

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.2.5
Fix Version/s: 10.2.8

Type: Bug Priority: Major
Reporter: Armin Preiml Assignee: Alexey Botchkov
Resolution: Done Votes: 1
Labels: JSON
Environment:

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);



 Comments   
Comment by Elena Stepanova [ 2017-05-12 ]

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)

Comment by Alexey Botchkov [ 2017-09-12 ]

The bug was fixed by an older commit.

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