Fix #144: invalid ternary operator priority

This commit is contained in:
bzick 2015-02-02 12:03:15 +03:00
parent a09b2f7620
commit f985fff314
2 changed files with 6 additions and 0 deletions

View File

@ -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;
}

View File

@ -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),