Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.0
-
None
Description
JSON_KEYS is documented to raise an error when the document is invalid.
Given a path, it reads only as far as the sub-object the path selects,
so a break anywhere outside that sub-object is never met.
SELECT JSON_KEYS('{"a":{"z":1} "b":2}', '$.a') AS v; |
v
|
["z"] |
No warning. Without the path, the same bytes are refused:
SELECT JSON_KEYS('{"a":1 "b":2}') AS v; |
v
|
NULL
|
Warnings:
|
Warning 4038 Syntax error in JSON text in argument 1 |
to function 'json_keys' at position 8 |
So the presence of a path argument decides whether an invalid document
is diagnosed.
How to repeat
SELECT JSON_KEYS('{"a":{"z":1} "b":2}', '$.a') AS v; -- ["z"], silent |
SELECT JSON_KEYS('{"a":{"z":1},"b":2,}', '$.a') AS v; -- ["z"], silent |
SELECT JSON_KEYS('[{"z":1} 2]', '$[0]') AS v; -- ["z"], silent |
Root cause
The walk stops at the end of the selected sub-object, so a break past
that end is never reached and the scanner never reports one. A break
inside the selected sub-object is met and does refuse the answer.
Contract, `scripts/fill_help_tables.sql:444` (topic 370): *"An error
will occur if JSON document is invalid, the path is invalid or if the
path contains a or * wildcard."* The wildcard half of that sentence is
honoured, as Warning 4044.
Affected versions
JSON_KEYS was added in 10.2.3.
Verified on 10.11 only (10.11.19-MariaDB-debug, commit 1dab253482d).
Other branches were not tested.
Note
Found while auditing the JSON functions against their documented
contracts. None. Every two-argument JSON_KEYS in the suite
has a well-formed outer document; func_json_invalid.test:74 covers
only the one-argument form.
Attachments
Issue Links
- split from
-
MDEV-40642 Project "JSON Phoenix" (placeholder)
-
- Open
-