[MDEV-27151] JSON_VALUE() does not parse NULL properties properly Created: 2021-12-01 Updated: 2022-10-07 Resolved: 2022-08-11 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3, 10.9.1 |
| Fix Version/s: | 10.3.37, 10.4.27, 10.5.18, 10.6.10, 10.7.6, 10.8.5, 10.9.3 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Assen Totin (Inactive) | Assignee: | Rucha Deodhar |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
A bug exists in the JSON_VALUE() function while parsing a JSON property that has a value of NULL. The function produces a string value "null" while it should actually produce a NULL value. The JSON standard clearly separates "null" as a string value from a NULL value for an object property (see Example 3 below). Example 1: Call the JSON_VALUE() function with a JSON where a property is set to NULL. Pay attention that the returned value of is lowercase; MariaDB CLI always prints the actual NULL values in uppercase in the result.
Example 2: Alternative way to verify the bug is to use PL/SQL code.
Example 3: Javascript code to illustrate the standard handling of NULL as a value of an object property through JSON serialisation(run under NodeJS):
|
| Comments |
| Comment by Oleksandr Byelkin [ 2022-08-01 ] | |||||||||||||||
|
There is other function which behave the same, and here is a bit better test to show difference:
result is:
| |||||||||||||||
| Comment by Oleksandr Byelkin [ 2022-08-01 ] | |||||||||||||||
|
Actually parser correctly set JSON_VALUE_NULL type, but it should be only correctly processed in val* methods. Item_func_json_extract::val_decimal even explicit put 0 value on it (I put there TODO marking to fix it). | |||||||||||||||
| Comment by Rucha Deodhar [ 2022-08-01 ] | |||||||||||||||
|
Patch: https://github.com/MariaDB/server/commit/8c667011a66fdbbe0cc4689f3886e174cf9045ba | |||||||||||||||
| Comment by Sergei Golubchik [ 2022-08-01 ] | |||||||||||||||
|
JSON_VALUE should definitely return NULL for JSON_VALUE_NULL.
See, the string is quoted "null", so a JSON NULL value should be null not SQL NULL. | |||||||||||||||
| Comment by Oleksandr Byelkin [ 2022-08-11 ] | |||||||||||||||
|
rucha174 add please json_extract un the test case (with comment why it is correct). just to 1) have coverage 2) if in the future we return to this again our decision will be documented and tested. After this it is OK to push. ah, and remove my TODO from the fources of json_extract. |