From a18562a58840abf68a0fc84130193feb2e74eb2a Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Fri, 24 May 2024 18:38:38 -0700 Subject: [PATCH] [5.x] Handle `null` in `bardText` modifier (#10199) --- src/Modifiers/CoreModifiers.php | 5 +++++ tests/Modifiers/BardTextTest.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Modifiers/CoreModifiers.php b/src/Modifiers/CoreModifiers.php index ee1f241977..bd2cf80792 100644 --- a/src/Modifiers/CoreModifiers.php +++ b/src/Modifiers/CoreModifiers.php @@ -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]; } diff --git a/tests/Modifiers/BardTextTest.php b/tests/Modifiers/BardTextTest.php index 496d3ea9a8..3dbb420581 100644 --- a/tests/Modifiers/BardTextTest.php +++ b/tests/Modifiers/BardTextTest.php @@ -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();