File tree Expand file tree Collapse file tree
user_guide_src/source/changelogs Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,7 +239,7 @@ protected function processRules(
239239 }
240240
241241 // Otherwise remove the if_exist rule and continue the process
242- $ rules = array_diff ($ rules , [ 'if_exist ' ] );
242+ $ rules = array_filter ($ rules , static fn ( $ rule ) => $ rule instanceof Closure || $ rule !== 'if_exist ' );
243243 }
244244
245245 if (in_array ('permit_empty ' , $ rules , true )) {
@@ -250,7 +250,7 @@ protected function processRules(
250250 $ passed = true ;
251251
252252 foreach ($ rules as $ rule ) {
253- if (preg_match ('/(.*?)\[(.*)\]/ ' , $ rule , $ match )) {
253+ if (! $ this -> isClosure ( $ rule ) && preg_match ('/(.*?)\[(.*)\]/ ' , $ rule , $ match )) {
254254 $ rule = $ match [1 ];
255255 $ param = $ match [2 ];
256256
@@ -275,7 +275,7 @@ protected function processRules(
275275 }
276276 }
277277
278- $ rules = array_diff ($ rules , [ 'permit_empty ' ] );
278+ $ rules = array_filter ($ rules , static fn ( $ rule ) => $ rule instanceof Closure || $ rule !== 'permit_empty ' );
279279 }
280280
281281 foreach ($ rules as $ i => $ rule ) {
Original file line number Diff line number Diff line change @@ -117,6 +117,12 @@ public function ifExistProvider(): Generator
117117 ['foo ' => []],
118118 true ,
119119 ],
120+ // Testing with closure
121+ [
122+ ['foo ' => ['if_exist ' , static fn ($ value ) => true ]],
123+ ['foo ' => []],
124+ true ,
125+ ],
120126 ];
121127 }
122128
@@ -275,6 +281,12 @@ public function providePermitEmptyCases(): Generator
275281 ['foo ' => '' , 'bar ' => 1 ],
276282 true ,
277283 ],
284+ // Testing with closure
285+ [
286+ ['foo ' => ['permit_empty ' , static fn ($ value ) => true ]],
287+ ['foo ' => '' ],
288+ true ,
289+ ],
278290 ];
279291 }
280292
Original file line number Diff line number Diff line change @@ -84,6 +84,12 @@ public function providePermitEmptyCasesStrict(): Generator
8484 ['foo ' => false ],
8585 true ,
8686 ],
87+ // Testing with closure
88+ [
89+ ['foo ' => ['permit_empty ' , static fn ($ value ) => true ]],
90+ ['foo ' => '' ],
91+ true ,
92+ ],
8793 ];
8894 }
8995
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ Deprecations
2424Bugs Fixed
2525**********
2626
27+ - **Validation: ** Fixed a bug where a closure used in combination with ``permit_empty `` or ``if_exist `` rules was causing an error.
28+
2729See the repo's
2830`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md >`_
2931for a complete list of bugs fixed.
You can’t perform that action at this time.
0 commit comments