Skip to content

Commit a7e812f

Browse files
committed
[BUGFIX] Allow null value as input for f:replace (#1282)
`null` can safely be converted to an empty string, so it's fine to allow it as a base string for string replacement. Resolves: #1279
1 parent db65e59 commit a7e812f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/ViewHelpers/ReplaceViewHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function render(): string
6767
$value = $this->arguments['value'] ?? $this->renderChildren();
6868
$search = $this->arguments['search'];
6969
$replace = $this->arguments['replace'];
70-
if ($value === null || (!is_scalar($value) && !$value instanceof \Stringable)) {
70+
if ($value !== null && !is_scalar($value) && !$value instanceof \Stringable) {
7171
throw new \InvalidArgumentException('A stringable value must be provided.', 1710441987);
7272
}
7373
if ($search === null) {

tests/Functional/ViewHelpers/ReplaceViewHelperTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ final class ReplaceViewHelperTest extends AbstractFunctionalTestCase
2020
{
2121
public static function throwsExceptionForInvalidArgumentDataProvider(): iterable
2222
{
23-
yield 'without value' => [
24-
'<f:replace search="foo" replace="bar" />',
25-
[],
26-
1710441987,
27-
'A stringable value must be provided.',
28-
];
2923
yield 'array as value' => [
3024
'{value -> f:replace(search: \'foo\', replace: \'bar\')}',
3125
['value' => [1, 2, 3]],
@@ -132,6 +126,11 @@ public static function renderDataProvider(): iterable
132126
['value' => ''],
133127
'',
134128
];
129+
yield 'with null as value' => [
130+
'<f:replace search="foo" replace="bar" value="{null}" />',
131+
[],
132+
'',
133+
];
135134
}
136135

137136
#[DataProvider('renderDataProvider')]

0 commit comments

Comments
 (0)