Skip to content

Graceful type handling #24

@thekid

Description

@thekid

The following raise "array to string conversion" exceptions - should be handle them more gracefully?

diff --git a/src/test/php/com/handlebarsjs/unittest/EachHelperTest.class.php b/src/test/php/com/handlebarsjs/unittest/EachHelperTest.class.php
index 1b664b6..6a71db2 100755
--- a/src/test/php/com/handlebarsjs/unittest/EachHelperTest.class.php
+++ b/src/test/php/com/handlebarsjs/unittest/EachHelperTest.class.php
@@ -304,4 +304,12 @@ class EachHelperTest extends HelperTest {
       ['locations' => ['KA' => ['names' => ['de_DE' => 'Karlsruhe', 'de_BW' => 'Karlsruh']]]]
     ));
   }
+
+  #[Test]
+  public function iterator_given_nested_array() {
+    Assert::equals('', $this->evaluate('{{#each names}}{{.}}{{/each}}', ['names' => [
+      [['en' => 'Hello', 'de' => 'Hallo']],
+      [['en' => 'World', 'de' => 'Welt']]
+    ]]));
+  }
 }
\ No newline at end of file
diff --git a/src/test/php/com/handlebarsjs/unittest/ExecutionTest.class.php b/src/test/php/com/handlebarsjs/unittest/ExecutionTest.class.php
index 4493cab..6789a99 100755
--- a/src/test/php/com/handlebarsjs/unittest/ExecutionTest.class.php
+++ b/src/test/php/com/handlebarsjs/unittest/ExecutionTest.class.php
@@ -37,6 +37,11 @@ class ExecutionTest {
     Assert::equals('', $this->evaluate('{{missing}}', []));
   }
 
+  #[Test]
+  public function given_array() {
+    Assert::equals('', $this->evaluate('{{names}}', ['names' => ['Hello', 'World']]));
+  }
+
   #[Test]
   public function html_special_chars_are_escaped() {
     Assert::equals('&quot;&lt;&amp;&gt;&#039;&quot;', $this->evaluate('{{name}}', ['name' => '"<&>\'"']));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions