-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: [Validation] field with asterisk (nested array) throws exception #5922
Comments
The error message seems to be expected behavior. The purpose is |
@kenjis the CodeIgniter4/system/Validation/Rules.php Line 302 in 051a578
$data = [
'a' => [
['b' => 1, 'c' => 2],
['c' => ''],
]
];
dd(dot_array_search('a.*.b', $data)); // 1
// Therefore, this test will fail.
$this->validation->setRules([
'a.*.c' => 'required_without[a.*.b]',
])->run([
'a' => [
['b' => 1, 'c' => 2],
['c' => ''],
]
]);
$this->assertSame(
'The a.*.c field is required when a.*.b is not present.',
$this->validation->getError('a.1.c')
); |
PHP Version
7.4
CodeIgniter4 Version
4.1.9
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
MySQL 4.9
What happened?
Case 1:
Case 2:
Case 3:
Steps to Reproduce
Case 1: validation throws an exception:
Argument 1 passed to CodeIgniter\Validation\Rules::exact_length() must be of the type string or null, array given, called in .*/vendor/codeigniter4/framework/system/Validation/Validation.php on line 292
.Case 2:
beneficiaries_accounts.account_1.account_number
validation successfully as expectedbeneficiaries_accounts.account_1.credit_amount
validation successfully as expected.beneficiaries_accounts.account_1.purpose
validation successfully as expected.Case 3:
beneficiaries_accounts.account_1.account_number
validation successfully as expectedbeneficiaries_accounts.account_1.credit_amount
validation successfully as expected.beneficiaries_accounts.account_1.purpose
validation successfully as expected.beneficiaries_accounts.account_2.account_number
validation successfully as expected.beneficiaries_accounts.account_2.credit_amount
validation successfully while value is null, and it's ignored required rule.beneficiaries_accounts.account_2.purpose
validation failsPurpose field must be at least 3 characters in length
, and it's ignored required_without rule.Expected Output
Case 1: expect validation fails without throws an exception
Case 3: validate each array separately
The text was updated successfully, but these errors were encountered: