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

Fix required_with rule bug. Fixes #1728 #1738

Merged
merged 3 commits into from
Feb 19, 2019
Merged
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: 2 additions & 2 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ public function required_with($str = null, string $fields, array $data): bool
// If the field is present we can safely assume that
// the field is here, no matter whether the corresponding
// search field is present or not.
$present = $this->required($data[$str] ?? null);
$present = $this->required($str ?? '');
Copy link
Member

Choose a reason for hiding this comment

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

Without going back and digging into the logic, are you sure this is correct? Using $str instead of $data[$str] would check that the current field is required, not that the with field is required...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. $str is field value. $data is Post data. so $data[$str] will never get the value.
show demo:
protected $validationRules = [ 'password' => 'required|min_length[8]', 'password_confirm' => 'matches[password]' ];

curl -X POST \ localhost/users \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H 'cache-control: no-cache' \ -d 'password=toto&password_confirm=toto'

$str is toto. $data['toto'] is null. so $present has always been false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested is no problem.


if ($present === true)
if ($present)
{
return true;
}
Expand Down