Skip to content

Commit cdec7d0

Browse files
committed
fix: revert rule alpha
1 parent 1ca24da commit cdec7d0

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

system/Validation/FormatRules.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class FormatRules
2929
*/
3030
public function alpha($str = null): bool
3131
{
32-
if (is_array($str)) {
33-
return false;
34-
}
35-
3632
if (! is_string($str)) {
3733
$str = (string) $str;
3834
}

tests/system/Validation/RulesTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\Test\CIUnitTestCase;
1717
use Config\Services;
18+
use ErrorException;
1819
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\Attributes\Group;
2021
use stdClass;
@@ -100,12 +101,6 @@ public static function provideIfExist(): iterable
100101
['foo' => ''],
101102
false,
102103
],
103-
// Invalid array input
104-
[
105-
['foo' => 'if_exist|alpha'],
106-
['foo' => ['bar' => '12345']],
107-
false,
108-
],
109104
// Input data does not exist then the other rules will be ignored
110105
[
111106
['foo' => 'if_exist|required'],
@@ -132,6 +127,19 @@ public static function provideIfExist(): iterable
132127
];
133128
}
134129

130+
public function testIfExistArray(): void
131+
{
132+
$this->expectException(ErrorException::class);
133+
$this->expectExceptionMessage('Array to string conversion');
134+
135+
$rules = ['foo' => 'if_exist|alpha'];
136+
// Invalid array input
137+
$data = ['foo' => ['bar' => '12345']];
138+
139+
$this->validation->setRules($rules);
140+
$this->validation->run($data);
141+
}
142+
135143
#[DataProvider('providePermitEmpty')]
136144
public function testPermitEmpty(array $rules, array $data, bool $expected): void
137145
{

tests/system/Validation/StrictRules/RulesTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@ public static function provideDiffers(): iterable
244244
'foo bar bool match' => [['foo' => true, 'bar' => true], false],
245245
];
246246
}
247+
248+
public function testIfExistArray(): void
249+
{
250+
$rules = ['foo' => 'if_exist|alpha'];
251+
// Invalid array input
252+
$data = ['foo' => ['bar' => '12345']];
253+
254+
$this->validation->setRules($rules);
255+
$this->assertFalse($this->validation->run($data));
256+
}
247257
}

0 commit comments

Comments
 (0)