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

Conversation

bangbangda
Copy link
Contributor

Description
Fix required_with rule bug.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@@ -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.

@Iamscalla
Copy link
Contributor

I agree with this PR, mind you, required_without has same issue. Treated it, but unable to submit a PR.

@lonnieezell lonnieezell merged commit 3b82e26 into codeigniter4:develop Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants