Skip to content

Commit 5a27bcd

Browse files
committed
Fixed TypeError in Regex strategy when expression evaluates to null.
1 parent d5944a3 commit 5a27bcd

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Strategy/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(
1818

1919
public function __invoke($data, $context = null)
2020
{
21-
if (preg_match($this->regex, parent::__invoke($data, $context), $matches)) {
21+
if (preg_match($this->regex, parent::__invoke($data, $context) ?? '', $matches)) {
2222
if (is_array($this->capturingGroup)) {
2323
return array_values(array_intersect_key($matches, array_flip($this->capturingGroup)));
2424
}

test/Unit/Mapper/Strategy/RegexTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public function testRegexMatchArray(): void
2929

3030
self::assertSame(['Alfa', 'Charlie'], $regex([]));
3131
}
32+
33+
public function testRegexMatchNullExpression(): void
34+
{
35+
$regex = (new Regex(null, '[Alfa]'))->setMapper(MockFactory::mockMapperEcho());
36+
37+
self::assertNull($regex([]));
38+
}
3239
}

0 commit comments

Comments
 (0)