Skip to content

fix: Handle non-array JSON in validation #8176

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ public function withRequest(RequestInterface $request): ValidationInterface
if (strpos($request->getHeaderLine('Content-Type'), 'application/json') !== false) {
$this->data = $request->getJSON(true);

if (! is_array($this->data)) {
$this->data = [];
}
Copy link
Member

Choose a reason for hiding this comment

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

What should we do when $this->data is not an array?
Is it okay just to throw the value away?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, if we have decided to use Validation, it must be in the key-value format. If it is a special format, Validation is not applicable. Validation doesn't need to be as comprehensive as JSON schema.


return $this;
}

Expand Down