Skip to content

Commit 192fca7

Browse files
committed
Fix block helper non-list array stringification
1 parent 07b4c2d commit 192fca7

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/Runtime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private static function resolveBlockResult(RuntimeContext $cx, mixed $result, mi
568568

569569
// Arrays stringify like JS Array.prototype.toString(), regardless of fn block.
570570
if (is_array($result)) {
571-
return implode(',', $result);
571+
return self::raw($result);
572572
}
573573

574574
if ($cb === null) {

tests/RegressionTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,13 @@ public static function helperProvider(): array
767767
],
768768
'block helper returning truthy non-string: stringified like JS' => [
769769
'template' => '{{#helper}}block{{/helper}}',
770-
'helpers' => ['helper' => fn() => ['truthy', 'array']],
771-
'expected' => 'truthy,array',
770+
'helpers' => ['helper' => fn() => ['a', ['ba', 'bb'], 'c']],
771+
'expected' => 'a,ba,bb,c',
772+
],
773+
'block helper returning non-list array: stringified like JS' => [
774+
'template' => '{{#helper}}block{{/helper}}',
775+
'helpers' => ['helper' => fn() => ['a' => 'foo', 'b' => 'bar']],
776+
'expected' => '[object Object]',
772777
],
773778
'inverted known block helper returning truthy non-string: stringified like JS' => [
774779
'template' => '{{^helper}}block{{/helper}}',

0 commit comments

Comments
 (0)