Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.0
-
None
Description
JSON_SEARCH is documented to warn and return NULL when the document is
not valid. Whether it does depends on the return argument: with
'one' it stops at the first hit and never reaches the check, with 'all'
it reads on and refuses.
SELECT JSON_SEARCH('{"a":"AB" "b":"AB"}', 'one', 'AB') AS v; |
v
|
"$.a"
|
|
|
SELECT JSON_SEARCH('{"a":"AB" "b":"AB"}', 'all', 'AB') AS v; |
v
|
NULL
|
Warnings:
|
Warning 4038 Syntax error in JSON text in argument 1 |
to function 'json_search' at position 11 |
Same document, same needle, opposite verdicts - decided by an argument
that says how many answers are wanted, not whether the document is one.
How to repeat
SELECT JSON_SEARCH('{"a":"AB" "b":"AB"}', 'one', 'AB') AS one_answers; |
SELECT JSON_SEARCH('{"a":"AB" "b":"AB"}', 'all', 'AB') AS all_refuses; |
|
|
SELECT JSON_SEARCH('{"a":"AB","b":}', 'one', 'AB') AS one_answers; |
SELECT JSON_SEARCH('{"a":"AB","b":}', 'all', 'AB') AS all_refuses; |
Root cause
The 'one' form jumps to the end at the first match, past the point where
the scanner's error is examined. The 'all' form walks the whole
document and reaches it.
Contract, `scripts/fill_help_tables.sql:462` (topic 388): *"A warning
will occur if the JSON document is not valid, any of the path arguments
are not valid, if return_arg is neither one nor all, or if the escape
character is not a constant. NULL will be returned."*
Affected versions
JSON_SEARCH 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. Partial, and it pins the defect:
func_json_invalid.result:268-270 records
JSON_SEARCH('{"a":"x",', 'one', 'x') = "$.a" with no warning. Every
other 'all' call in the suite uses a valid document, so nothing pins
the asymmetry.
Attachments
Issue Links
- split from
-
MDEV-40642 Project "JSON Phoenix" (placeholder)
-
- Open
-