← Back to team overview

maria-discuss team mailing list archive

Json validation of unicode escaped strings

 

I am trying to insert json data in to a table with json check
constraint. The non-ascii characters are unicode escaped.
This fails in cases where the string in the json data has unicode
points in non-BMP plane, e.g U+1F449.

Error:
ERROR 4025 (23000): CONSTRAINT `js` failed for `t`.`t`

The same json works if the unicode characters are encoded in utf-8 and
not escaped.

I think I can confirm that this is a json validation error with json_valid.

MariaDB [t]> show create table t;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table       |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `js` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
CHECK (json_valid(`js`)),
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [t]> select json_valid('{"test": "\\ud83d\\ude0b"}');
+------------------------------------------+
| json_valid('{"test": "\\ud83d\\udc49"}') |
+------------------------------------------+
|                                        0 |
+------------------------------------------+
1 row in set (0.00 sec)


This is on Maria 10.3

MariaDB [t]> select version();
+----------------+
| version()      |
+----------------+
| 10.3.8-MariaDB |
+----------------+


So, my questions, are unicode escaped strings in json supported? Is
this a bug or a limitation?
I have searched for this issue and have failed to come up with anything.

Thanks,
Manoj


Follow ups