[MDEV-26679] JSON_VALID validates invalid JSON Created: 2021-09-25  Updated: 2021-09-25  Resolved: 2021-09-25

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-26678 JSON_EQUALS validates invalid JSON an... Closed

 Description   

10.7.0 d552e092c9f3e20da078d1b62b976f629f73d3a4 (Debug)

10.7.0-dbg>SELECT JSON_VALID('{}');
+------------------+
| JSON_VALID('{}') |
+------------------+
|                1 |
+------------------+
1 row in set (0.000 sec)
 
10.7.0-dbg>SELECT JSON_VALID('{\}');
+-------------------+
| JSON_VALID('{\}') |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.000 sec)

Both, at least according to http://json-validator.com/ are invalid. The second is definitely invalid/cannot be valid.



 Comments   
Comment by Roel Van de Paar [ 2021-09-25 ]

Also:

10.7.0 d552e092c9f3e20da078d1b62b976f629f73d3a4 (Debug)

10.7.0-dbg>SELECT JSON_VALID('{ \ \ \ \ \ \ \ \ }');
+-----------------------------------+
| JSON_VALID('{ \ \ \ \ \ \ \ \ }') |
+-----------------------------------+
|                                 1 |
+-----------------------------------+
1 row in set (0.000 sec)

Comment by Sergei Golubchik [ 2021-09-25 ]

examples with backslash are no different from empty curly braces:

MariaDB [test]> select '{\}', '{ \ \ \ \ \ \ \ \ }';
+----+-------------+
| {} | {         } |
+----+-------------+
| {} | {         } |
+----+-------------+
1 row in set (0.001 sec)

see https://mariadb.com/kb/en/string-literals/
If you disable backslash escapes, these strings won't be valid json anymore

MariaDB [test]> set sql_mode=no_backslash_escapes;
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> select json_valid('{\}'), json_valid('{ \ \ \ \ \ \ \ \ }');
+-------------------+-----------------------------------+
| json_valid('{\}') | json_valid('{ \ \ \ \ \ \ \ \ }') |
+-------------------+-----------------------------------+
|                 0 |                                 0 |
+-------------------+-----------------------------------+
1 row in set (0.001 sec)

As far as the empty json {} is concerned, there are two JSON standards, ECMA-404 (https://www.ecma-international.org/publications-and-standards/standards/ecma-404/) and ISO STD 90 (https://www.rfc-editor.org/info/std90). Both agree that {} is a valid json.

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