Skip to content

Commit

Permalink
fix: is_image causes PHP 8.1 deprecated error
Browse files Browse the repository at this point in the history
ErrorException : mb_strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
.../CodeIgniter4/system/Validation/FileRules.php:138
  • Loading branch information
kenjis committed Jun 19, 2022
1 parent 44cbd89 commit 18f7e8c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Validation/FileRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function is_image(?string $blank, string $params): bool

// We know that our mimes list always has the first mime
// start with `image` even when then are multiple accepted types.
$type = Mimes::guessTypeFromExtension($file->getExtension());
$type = Mimes::guessTypeFromExtension($file->getExtension()) ?? '';

if (mb_strpos($type, 'image') !== 0) {
return false;
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/system/Validation/FileRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ final class FileRulesTest extends CIUnitTestCase

protected function setUp(): void
{
$this->resetServices();
parent::setUp();

$this->validation = new Validation((object) $this->config, Services::renderer());
$this->validation->reset();

Expand Down Expand Up @@ -229,6 +231,7 @@ public function testIsntImage(): void
'type' => 'application/address',
'error' => UPLOAD_ERR_OK,
];

$this->validation->setRules(['avatar' => 'is_image[stuff]']);
$this->assertFalse($this->validation->run([]));
}
Expand Down

0 comments on commit 18f7e8c

Please sign in to comment.