From 89f2e23750408cf10e375d60a617210f9b762e7e Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 2 Feb 2015 11:49:42 +0300 Subject: [PATCH 1/4] Fix #144: forgot prepend unary operator --- src/Fenom/Template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index e80f735..c8d61e3 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -780,7 +780,7 @@ class Template extends Render if ($this->_options & Fenom::DENY_METHODS) { throw new \LogicException("Forbidden to call methods"); } - return $this->parseChain($tokens, $code); + return $unary . $this->parseChain($tokens, $code); } elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) { if($this->_options & Fenom::FORCE_VERIFY) { return $unary . '(isset(' . $code . ') ? ' . $code . $tokens->getAndNext() . ' : null)'; From a09b2f7620fec63e6ce66f8ef002672137631bea Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 2 Feb 2015 12:02:30 +0300 Subject: [PATCH 2/4] Fix #135 (repeat commit) --- src/Fenom/Tokenizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fenom/Tokenizer.php b/src/Fenom/Tokenizer.php index 4a0ad6d..217e151 100644 --- a/src/Fenom/Tokenizer.php +++ b/src/Fenom/Tokenizer.php @@ -83,7 +83,7 @@ class Tokenizer public static $macros = array( self::MACRO_STRING => array( \T_ABSTRACT => 1, \T_ARRAY => 1, \T_AS => 1, \T_BREAK => 1, - \T_BREAK => 1, \T_CASE => 1, \T_CATCH => 1, \T_CLASS => 1, + \T_CASE => 1, \T_CATCH => 1, \T_CLASS => 1, \T_CLASS_C => 1, \T_CLONE => 1, \T_CONST => 1, \T_CONTINUE => 1, \T_DECLARE => 1, \T_DEFAULT => 1, \T_DIR => 1, \T_DO => 1, \T_ECHO => 1, \T_ELSE => 1, \T_ELSEIF => 1, \T_EMPTY => 1, From f985fff3149d94f6a960fc71d9dc3f1783d3492d Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 2 Feb 2015 12:03:15 +0300 Subject: [PATCH 3/4] 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), From d5417630ac32f13e0f8e4c39b953d411ef321887 Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 2 Feb 2015 12:05:02 +0300 Subject: [PATCH 4/4] Add test for #144 (condition) --- tests/cases/Fenom/TemplateTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index 9a71dc8..0107315 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -659,6 +659,7 @@ class TemplateTest extends TestCase array('{$a ? "right" : "no way"}', $a), array('{1 ? "right" : "no way"}', $a), array('{$a == 1 ? "right" : "no way"}', $a), + array('{$a > 0 ? "right" : "no way"}', $a), // ! array('{if $a!} right {/if}', $a), array('{if 1!} right {/if}', $a),