-
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 passes if key does not exist when using asterisk #8006
Comments
Thank you for reporting. I've confirmed the behavior. |
@kenjis You can assign me to handle this bug. |
@ping-yee Assigned. |
Yah, I just figure out how the current code works.
I will follow this way to fix this bug. |
@ping-yee Any progress? |
@kenjis Yah, but this is not very optimistic and I need your help. |
I think this is very difficult problem. So it requires more brains. |
Yes, I agree with this and I send the draft PR. |
As a workaround, you can use |
i can confirm that if using with no asterisks the validation still not works using data like this $requestData = [
'contacts' => [
'friend' => 'test'
]
];
$this->validator = Services::validation();
$this->validator->setRules(
[
'contacts.friend' => 'required',
]
);
dd($this->validator->run($requestData), $this->validator->getErrors()); |
PHP Version
8.1
CodeIgniter4 Version
4.4.1 OR 4.3.5
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
If I use the asterisk in the validation rule, it does not check for non existing key.
There are two workarounds, but I guess they are not the best solutions.
Steps to Reproduce
In any controller I use the following snippet in the initController method.
Expected Output
I think the validation should check for it and fail if key does not exist (if there is a rule for it). So in my case the output should be:
$this->validator->run(...) boolean false
$this->validator->getErrors() array (1)
contacts.friends.1.name => string (46) "The contacts.friends.*.name field is required."
Now I get this:
$this->validator->run(...) boolean true
$this->validator->getErrors() array (0)
Anything else?
I did not see any reference in the documentation: https://codeigniter.com/user_guide/libraries/validation.html#setting-rules-for-array-data
I did not find any issue like this (maybe in the closed issues).
The text was updated successfully, but these errors were encountered: