Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Liquid/StandardFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ public static function prepend($input, $string)
* Remove a substring
*
* @param string $input
* @param string $string
* @param string|null $string
*
* @return string
*/
public static function remove($input, $string)
{
return str_replace($string, '', $input);
return self::replace($input, $string);
}


Expand All @@ -441,15 +441,18 @@ public static function remove_first($input, $string)
/**
* Replace occurrences of a string with another
*
* @param string $input
* @param string $string
* @param string $replacement
* @param string|null $input
* @param string|null $string
* @param string|null $replacement
*
* @return string
*/
public static function replace($input, $string, $replacement = '')
{
return str_replace($string, $replacement, $input);
if ($string === null) {
return $input;
}
return str_replace($string, (string)$replacement, (string)$input);
}


Expand Down
14 changes: 14 additions & 0 deletions tests/Liquid/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,18 @@ public function testFilterArrayNull()

$this->assertTemplateResult($expected, $text, []);
}

public function testRemoveWithNull(): void
{
$text = ' {{ best_cars | remove: brand }} ';

$this->assertTemplateResult(' bmw ', $text, [...$this->assigns, 'brand' => null]);
}

public function testReplaceWithNull()
{
$text = ' {{ best_cars | replace: brand }} ';

$this->assertTemplateResult(' bmw ', $text, [...$this->assigns, 'brand' => null]);
}
}
Loading