Skip to content

Commit 8a179ac

Browse files
committed
fix: add uploaded and is_image to field-referencing validation rules
1 parent f8f95d7 commit 8a179ac

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎system/Validation/Validation.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Validation implements ValidationInterface
4242
'differs',
4343
'required_with',
4444
'required_without',
45+
'uploaded',
46+
'is_image',
4547
];
4648

4749
/**

‎tests/system/Validation/ValidationTest.php‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,13 +1891,27 @@ public function testParamResolvesFieldLabelForFieldReferenceRules(): void
18911891
'label' => 'Password Confirmation',
18921892
'rules' => 'matches[password]',
18931893
],
1894+
'userfile' => [
1895+
'label' => 'Profile Avatar',
1896+
'rules' => 'permit_empty',
1897+
],
1898+
'avatar' => [
1899+
'label' => 'Avatar',
1900+
'rules' => 'uploaded[userfile]',
1901+
'errors' => [
1902+
'uploaded' => 'Invalid file uploaded for {param}.',
1903+
],
1904+
],
18941905
];
18951906

18961907
$this->validation->setRules($rules);
18971908

18981909
$this->assertFalse($this->validation->run(['password' => 'abc', 'password_confirmation' => 'def']));
18991910
$this->assertSame(
1900-
['password_confirmation' => 'The Password Confirmation field does not match the Password field.'],
1911+
[
1912+
'password_confirmation' => 'The Password Confirmation field does not match the Password field.',
1913+
'avatar' => 'Invalid file uploaded for Profile Avatar.',
1914+
],
19011915
$this->validation->getErrors(),
19021916
);
19031917
}

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Bugs Fixed
5959
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
6060
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
6161
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
62-
- **Validation:** Fixed a bug where a rule parameter that was not a field reference (e.g., a numeric limit) could resolve another field's label and leak it into the error message when it matched a defined field name. Label substitution now only applies to field-referencing rules (``matches``, ``differs``, ``required_with``, ``required_without``).
62+
- **Validation:** Fixed a bug where a rule parameter that was not a field reference (e.g., a numeric limit) could resolve another field's label and leak it into the error message when it matched a defined field name. Label substitution now only applies to field-referencing rules (``matches``, ``differs``, ``required_with``, ``required_without``, ``uploaded``, ``is_image``).
6363

6464
See the repo's
6565
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)