From f985fff3149d94f6a960fc71d9dc3f1783d3492d Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 2 Feb 2015 12:03:15 +0300 Subject: [PATCH] Fix #144: invalid ternary operator priority --- src/Fenom/Template.php | 4 ++++ tests/cases/Fenom/TemplateTest.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index c8d61e3..e5f7bde 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -667,6 +667,10 @@ class Template extends Render $var = false; } if ($tokens->is('?', '!')) { + if($cond) { + $term = array_pop($exp) . ' ' . $term; + $term = '('. array_pop($exp) . ' ' . $term . ')'; + } $term = $this->parseTernary($tokens, $term, $var); $var = false; } diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index 22af39e..9a71dc8 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -106,6 +106,7 @@ class TemplateTest extends TestCase array('hello, {"World"}!', $a, 'hello, World!'), array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'), array('hello, {$world->chunk(1)->self->chunk("new")}!', $b, 'hello, world!'), + array('hello, {!$world->chunk(1)->self->chunk("new")}!', $b, 'hello, !'), array(':: {Fenom\Helper::method()->page->title} ::', $b, ':: test page ::'), ); } @@ -657,6 +658,7 @@ class TemplateTest extends TestCase array('{0 ? "no way" : "right"}', $a), array('{$a ? "right" : "no way"}', $a), array('{1 ? "right" : "no way"}', $a), + array('{$a == 1 ? "right" : "no way"}', $a), // ! array('{if $a!} right {/if}', $a), array('{if 1!} right {/if}', $a),