Commit 0887207e by seldaek

Fixed a bug in {tif} that didn't work when 0 was given as the true or false value

git-svn-id: http://svn.dwoo.org/trunk@318 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 27642e40
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
* Fixed a bug when accessing array indices that contain a minus sign, it * Fixed a bug when accessing array indices that contain a minus sign, it
is now possible to access those using {$var[index-foo]}, is now possible to access those using {$var[index-foo]},
{$var['index-foo']} or {$index="index-foo"} {$var[$index]} {$var['index-foo']} or {$index="index-foo"} {$var[$index]}
* Fixed a bug in {tif} that didn't work when 0 was given as the true or
false value
* Fixed a bug when using the autoEscape feature with sub-templates (the * Fixed a bug when using the autoEscape feature with sub-templates (the
compiled sub-template couldn't access the dwoo charset property, compiled sub-template couldn't access the dwoo charset property,
resulting in a fatal error) resulting in a fatal error)
......
...@@ -28,7 +28,7 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest) ...@@ -28,7 +28,7 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif'); throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif');
} }
} }
if (count($rest) == 1) { if (count($rest) == 1) {
return $rest[0]; return $rest[0];
} }
...@@ -40,6 +40,9 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest) ...@@ -40,6 +40,9 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
// remove the ':' if present // remove the ':' if present
array_pop($rest); array_pop($rest);
} elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) { } elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) {
if ($falseResult === '?' || $falseResult === ':') {
throw new Dwoo_Compilation_Exception($compiler, 'Tif: incomplete tif statement, value missing after '.$falseResult);
}
// there was in fact no false result provided, so we move it to be the true result instead // there was in fact no false result provided, so we move it to be the true result instead
$trueResult = $falseResult; $trueResult = $falseResult;
$falseResult = "''"; $falseResult = "''";
...@@ -60,12 +63,12 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest) ...@@ -60,12 +63,12 @@ function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
} }
// check params were correctly provided // check params were correctly provided
if (empty($rest) || empty($trueResult) || empty($falseResult)) { if (empty($rest) || $trueResult === null || $falseResult === null) {
throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>'); throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
} }
// parse condition // parse condition
$condition = Dwoo_Plugin_if::replaceKeywords($rest, $compiler); $condition = Dwoo_Plugin_if::replaceKeywords($rest, $compiler);
return '(('.implode(' ', $condition).') ? '.($trueResult===true ? implode(' ', $condition) : $trueResult).' : '.$falseResult.')'; return '(('.implode(' ', $condition).') ? '.($trueResult===true ? implode(' ', $condition) : $trueResult).' : '.$falseResult.')';
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment