-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql:
tree.ParseJSON
should not ignore trailing data
`tree.ParseJSON` uses `Decoder.More()` method to determine if the input contains trailing data. The implementation made incorrect assumptions as to the reason why `Decoder.More()` allows input to contain `]` or `}` characters, even when JSON object has been consumed. This PR fixes and comments those faulty assumptions, and fixes multiple existing tests that seemed to rely on those faulty assumptions. In particular, prior to this PR, the following input would be allowed (i.e. extra end of object character `}`): ``` [email protected]:26257/movr> select '{"longKey1":"longValue1"}}'::jsonb; jsonb ------------------------------ {"longKey1": "longValue1"} (1 row) ``` But so would the following be allowed: ``` [email protected]:26257/movr> select '{"longKey1":"longValue1"}} should this data be ignored?'::jsonb; jsonb ------------------------------ {"longKey1": "longValue1"} (1 row) ``` So, the issue is: if above conversion was executed to insert JSONB into the database, we would silently truncate (corrupt) JSON input, and instead of returning an error, we would return success. This behavior is wrong, and this PR fixes it so that an error is returned: ``` select '{"longKey1":"longValue1"}} should this data be ignored?'::jsonb; ERROR: could not parse JSON: trailing characters after JSON document SQLSTATE: 22P02 ``` Release note (bug fix): Do not silently truncate trailing characters when attemption to convert corrupt JSON string input into JSONb.
- Loading branch information
Yevgeniy Miretskiy
committed
Oct 13, 2022
1 parent
b955fd6
commit f2d5001
Showing
3 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters