Fix ternary operator

This commit is contained in:
bzick
2013-08-02 23:01:06 +04:00
parent e51eb9f3d8
commit 43925ae640
2 changed files with 6 additions and 4 deletions

View File

@ -907,9 +907,7 @@ class Template extends Render
} }
} else { } else {
$expr1 = $this->parseExp($tokens, true); $expr1 = $this->parseExp($tokens, true);
if (!$tokens->is(":")) { $tokens->need(':')->skip();
throw new UnexpectedTokenException($tokens, null, "ternary operator");
}
$expr2 = $this->parseExp($tokens, true); $expr2 = $this->parseExp($tokens, true);
if ($empty) { if ($empty) {
return '(empty(' . $var . ') ? ' . $expr2 . ' : ' . $expr1 . ')'; return '(empty(' . $var . ') ? ' . $expr2 . ' : ' . $expr1 . ')';

View File

@ -404,7 +404,11 @@ class TemplateTest extends TestCase
array('{if $nonempty.double!} right {/if}', $a), array('{if $nonempty.double!} right {/if}', $a),
array('{if $nonempty.bool!} right {/if}', $a), array('{if $nonempty.bool!} right {/if}', $a),
// ! ... : ... // ! ... : ...
array('{$unexists ! "no way" : "right"}', $a),
array('{$a ! "right" : "no way"}', $a),
// !: ... // !: ...
array('{$unexists !: "right"}', $a),
array('{$a !: "right"}', $a, '1'),
); );
} }
@ -673,7 +677,7 @@ class TemplateTest extends TestCase
public function _testSandbox() public function _testSandbox()
{ {
try { try {
var_dump($this->fenom->compileCode('{if 0 is empty} block1 {else} block2 {/if}')->getBody()); var_dump($this->fenom->compileCode('{$a!"no way":"right"}')->getBody());
} catch (\Exception $e) { } catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString()); print_r($e->getMessage() . "\n" . $e->getTraceAsString());
} }