Skip to content

Commit 3eec126

Browse files
committed
fix: add uploaded and is_image to field-referencing validation rules
1 parent 7c90c79 commit 3eec126

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
@@ -61,7 +61,7 @@ Bugs Fixed
6161
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
6262
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
6363
- **Validation:** Fixed a bug where ``valid_cc_number`` accepted non-digit characters (e.g., a decimal point) in the card number. Such values could pass the Luhn check and triggered an ``Undefined array key`` warning inside it; the number is now checked with ``ctype_digit()``.
64-
- **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``).
64+
- **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``).
6565

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

0 commit comments

Comments
 (0)