Skip to content

Commit b0faeb8

Browse files
committed
Fix findbyid with null parameter
1 parent ac0bd8d commit b0faeb8

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Mvc/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public static function findFirst(array $parameters = []): ?CollectionInterface
869869
public static function findById($id): ?CollectionInterface
870870
{
871871
if (!is_object($id)) {
872-
if (!preg_match("/^[a-f\d]{24}$/i", $id)) {
872+
if (!preg_match("/^[a-f\d]{24}$/i", (string)$id)) {
873873
return null;
874874
}
875875

tests/integration/Collection/FindByIdCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function mvcCollectionFindById(IntegrationTester $I)
7171
{
7272
$I->wantToTest('Mvc\Collection - findById()');
7373

74+
$I->assertNull(Robots::findById(null));
7475
$I->assertNull(Robots::findById(new ObjectId()));
7576
$I->assertInstanceOf(Robots::class, Robots::findById($this->tmpId));
7677
$I->assertInstanceOf(Robots::class, Robots::findById((string)$this->tmpId));

0 commit comments

Comments
 (0)