Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the end of input when parsing JSON #10783

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

kasiafi
Copy link
Member

@kasiafi kasiafi commented Jan 25, 2022

fixes #10724

@cla-bot cla-bot bot added the cla-signed label Jan 25, 2022
@kasiafi
Copy link
Member Author

kasiafi commented Jan 25, 2022

fixes #10724

@kasiafi kasiafi requested a review from findepi January 25, 2022 10:26
@kasiafi
Copy link
Member Author

kasiafi commented Jan 25, 2022

@findepi this is based on #10720 so that I could update tests. Also, rebased on master.

Copy link
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findepi this is based on #10720 so that I could update tests. Also, rebased on master.

Feel free to un-base. I will rebase #10720 once this one is merged.

assertFails("SELECT JSON '{}{abc'")
.hasErrorCode(INVALID_LITERAL);
assertFails("SELECT JSON '{}abc'")
.hasErrorCode(INVALID_LITERAL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have tests with json_parse invocation too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@kasiafi kasiafi force-pushed the 307JsonParse branch 2 times, most recently from eaa2d56 to 3ade9c2 Compare January 25, 2022 13:47
Before this change, the end of input after reading a JSON value
was not properly validated:
- if there were remaining characters which did not parse as JSON,
  exception was thrown. E.g. `'["correct JSON"]and more'` failed
- if there were remaining characters which formed a valid token,
  they were silently ignored. E.g. `'["correct JSON"]{and more'`
  succeeded and returned `'["correct JSON"]'`

After this change, any trailing characters are caught and reported
as error.
@kasiafi kasiafi requested a review from findepi January 27, 2022 08:06
@kasiafi kasiafi merged commit a7bc2ba into trinodb:master Jan 27, 2022
@github-actions github-actions bot added this to the 370 milestone Jan 27, 2022
v-jizhang added a commit to v-jizhang/presto that referenced this pull request Feb 28, 2022
Cherry-pick of trinodb/trino#10783

Before this change, the end of input after reading a JSON value
was not properly validated:
- if there were remaining characters which did not parse as JSON,
  exception was thrown. E.g. `'["correct JSON"]and more'` failed
- if there were remaining characters which formed a valid token,
  they were silently ignored. E.g. `'["correct JSON"]{and more'`
  succeeded and returned `'["correct JSON"]'`

After this change, any trailing characters are caught and reported
as error.

Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

No error for json_parse() or JSON literal with trailing payload
3 participants