Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graceful type handling #24

Open
thekid opened this issue Nov 13, 2022 · 0 comments
Open

Graceful type handling #24

thekid opened this issue Nov 13, 2022 · 0 comments
Labels

Comments

@thekid
Copy link
Member

thekid commented Nov 13, 2022

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' => '"<&>\'"']));
thekid added a commit to thekid/dialog that referenced this issue Nov 13, 2022
Prevents attributes containing arrays or maps from breaking rendering
with an "array to string" conversion error, see xp-forge/handlebars#24

This will permit us to refactor meta data more freely in the future,
e.g. as see in the "Extract colors" pull request, #36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant