Skip to content

Commit

Permalink
Fix join modifier when value is null (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell authored Dec 11, 2020
1 parent 7b7a1bc commit 3f8a220
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ public function image($value, $params)
*/
public function joinplode($value, $params)
{
if (is_null($value)) {
return '';
}

// Workaround to support pipe characters. If there are multiple params
// that means a pipe was used. We'll just join them for now.
if (count($params) > 1) {
Expand Down
21 changes: 21 additions & 0 deletions tests/Modifiers/JoinTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tests\Modifiers;

use Statamic\Modifiers\Modify;
use Tests\TestCase;

class JoinTest extends TestCase
{
/** @test */
public function it_returns_empty_string_when_value_is_null()
{
$joined = $this->modify(null);
$this->assertEquals('', $joined);
}

public function modify($arr, $delimiter = ' ')
{
return Modify::value($arr)->join($delimiter)->fetch();
}
}

0 comments on commit 3f8a220

Please sign in to comment.