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: Validation cannot handle array item #5405

Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Nov 29, 2021

Description
Supersedes #5402
Fixes #5368

  • separate validation process of multiple field and single field

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 29, 2021
@kenjis kenjis mentioned this pull request Nov 29, 2021
5 tasks
@kenjis kenjis requested a review from MGatner December 2, 2021 07:24
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

The code is a bit hard to review on mobile but what I see all looks good, and the tests are great.

Your User Guide write-up is very thorough, but I would rather see that in the changelogs (i.e. user_guide_src/source/changelogs/v4.1.6.rst) and keep the Upgrading section as actual tasks that need to be done when upgrading. A simple sentence with reference to the longer explanation in the changelog would be good, like "Due to a bug fix Validation now might ____ (see ____.rst), so make sure you ____ to any code calling it."

@MGatner
Copy link
Member

MGatner commented Dec 4, 2021

Will this conflict with the Strict Validation changes?

@kenjis kenjis force-pushed the fix-validation-cannot-handle-array-data branch from 43757f8 to 9115994 Compare December 5, 2021 02:25
@kenjis
Copy link
Member Author

kenjis commented Dec 5, 2021

@MGatner I added the last commit to fix the docs. I rebased because the commits are not verified.

Will this conflict with the Strict Validation changes?

No.
#5402 will be split into two PRs. This is one.

@kenjis kenjis requested a review from MGatner December 5, 2021 03:46
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Doc changes look good! Since this is a breaking change I'd like it if you could get another reviewer. I'll ping the team on Slack.

@kenjis kenjis force-pushed the fix-validation-cannot-handle-array-data branch from 9115994 to 0485bb7 Compare December 6, 2021 01:57
}
} else {
// Process single field
$this->processRules($field, $setup['label'] ?? $field, $values, $rules, $data);
Copy link
Member

Choose a reason for hiding this comment

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

Since this one is the same with L145, I think we can combine this with that?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I remove the if statement from L143, tests in tests/system/Validaton/ passes.
But I'm not sure removing it causes no problem.

What input makes $values empty array?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added continue in the if to fix the bug that $this->processRules() run twice.

Copy link
Member

Choose a reason for hiding this comment

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

What input makes $values empty array?

This is raised in an issue report. I'll check.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I read the comment and the fix PR.
But I'm not sure we can remove the if ($values === []) { ... }.
I feel it is safer not to remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@paulbalandan I want to update upgrade_416.rst, so I merge this for now.

system/Validation/Validation.php Outdated Show resolved Hide resolved
system/Validation/Validation.php Outdated Show resolved Hide resolved
user_guide_src/source/changelogs/v4.1.6.rst Outdated Show resolved Hide resolved
kenjis and others added 4 commits December 6, 2021 21:29
Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>
Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>
@kenjis kenjis merged commit 90edc48 into codeigniter4:develop Dec 8, 2021
@kenjis kenjis deleted the fix-validation-cannot-handle-array-data branch December 8, 2021 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Validation rule can't handle array data
5 participants