Skip to content

Commit

Permalink
[5.x] Handle null in bardText modifier (#10199)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell authored May 25, 2024
1 parent 8b8da8e commit a18562a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ public function bardText($value)
if ($value instanceof Value) {
$value = $value->raw();
}

if (is_null($value)) {
return '';
}

if (Arr::isAssoc($value)) {
$value = [$value];
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Modifiers/BardTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public function it_extracts_bard_text_from_value_object()
$this->assertEquals($expected, $this->modify($data));
}

/** @test */
public function it_handles_null()
{
$this->assertEquals('', $this->modify(null));
}

public function modify($arr, ...$args)
{
return Modify::value($arr)->bard_text($args)->fetch();
Expand Down

0 comments on commit a18562a

Please sign in to comment.