Skip to content

Commit 16b027f

Browse files
committed
fix: separate process of multiple field and single field
1 parent 6b3121d commit 16b027f

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

system/Validation/Validation.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,20 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
139139
}
140140

141141
$values = dot_array_search($field, $data);
142-
$values = is_array($values) ? $values : [$values];
143142

144143
if ($values === []) {
145144
// We'll process the values right away if an empty array
146145
$this->processRules($field, $setup['label'] ?? $field, $values, $rules, $data);
147146
}
148147

149-
foreach ($values as $value) {
150-
// Otherwise, we'll let the loop do the job
151-
$this->processRules($field, $setup['label'] ?? $field, $value, $rules, $data);
148+
if (strpos($field, '*') !== false && is_array($values)) {
149+
// Process multiple fields
150+
foreach ($values as $value) {
151+
$this->processRules($field, $setup['label'] ?? $field, $value, $rules, $data);
152+
}
153+
} else {
154+
// Process single field
155+
$this->processRules($field, $setup['label'] ?? $field, $values, $rules, $data);
152156
}
153157
}
154158

tests/system/Validation/FormatRulesTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,11 @@ public function testNumericWithInvalidTypeData($value, bool $expected): void
837837

838838
public function integerInvalidTypeDataProvider(): Generator
839839
{
840-
yield 'array with int' => [
841-
[555],
842-
true, // incorrect
843-
];
840+
// TypeError : CodeIgniter\Validation\FormatRules::integer(): Argument #1 ($str) must be of type ?string, array given
841+
// yield 'array with int' => [
842+
// [555],
843+
// false,
844+
// ];
844845

845846
// TypeError : CodeIgniter\Validation\FormatRules::integer(): Argument #1 ($str) must be of type ?string, array given
846847
// yield 'empty array' => [

tests/system/Validation/ValidationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function arrayDataProvider(): Generator
119119
{
120120
yield 'list array' => [
121121
[1, 2, 3, 4, 5],
122-
false, // incorrect
122+
true,
123123
];
124124

125125
yield 'associative array' => [
@@ -128,7 +128,7 @@ public function arrayDataProvider(): Generator
128128
'role' => 'administrator',
129129
'usepass' => 0,
130130
],
131-
false, // incorrect
131+
true,
132132
];
133133

134134
yield 'int' => [
@@ -171,7 +171,7 @@ public function isIntInvalidTypeDataProvider(): Generator
171171
{
172172
yield 'array with int' => [
173173
[555],
174-
true, // incorrect
174+
false,
175175
];
176176

177177
yield 'empty array' => [

0 commit comments

Comments
 (0)