Commit 93275b7f by seldaek

Fixes parsing of vars with string keys that was too greedy [fixes #20]

git-svn-id: svn://dwoo.org/dwoo/trunk@250 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent a18ac290
[2009--] 1.1.0 [2009--] 1.1.0
+ Added {template} plugin that allows you to define sub-templates and then + Added {template} plugin that allows you to define sub-templates and then
call them (even recursively) call them (works recursively too, good for menus and lists)
+ Added {load_templates} to load external sub-templates into your file + Added {load_templates} to load external sub-templates into your file
+ Allowed string concatenation assignments with {$foo.="bar"} + Allowed string concatenation assignments with {$foo.="bar"}
* Many new unit tests to improve code coverage and a bunch of bug fixes
that resulted, but I didn't really keep track of them
* Fixed a bug with parsing AND/OR keywords in conditionals when they were * Fixed a bug with parsing AND/OR keywords in conditionals when they were
followed by round brackets followed by round brackets
* Fixed assignments not handling multi-line values correctly * Fixed assignments not handling multi-line values correctly
* Fixed parameter parsing issue when a plugin name was all uppercased * Fixed parameter parsing issue when a plugin name was all uppercased
* Fixes assignments failing with autoEscape enabled * Fixed assignments failing with autoEscape enabled
* Fixed parsing of vars with string keys that was too greedy
* Dwoo_Template::$chmod is now enforced for directories as well (#18) * Dwoo_Template::$chmod is now enforced for directories as well (#18)
* Many new unit tests to improve code coverage and a bunch of bug fixes
that resulted, but I didn't really keep track of them
[2008-12-24] 1.0.1 [2008-12-24] 1.0.1
* Direct assignments like {$foo = 5} now allow spaces around the operator * Direct assignments like {$foo = 5} now allow spaces around the operator
......
...@@ -1956,7 +1956,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1956,7 +1956,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
{ {
$substr = substr($in, $from, $to-$from); $substr = substr($in, $from, $to-$from);
if (preg_match('#(\$?\.?[a-z0-9_:]*(?:(?:(?:\.|->)(?:[a-z0-9_:]+|(?R))|\[(?:[a-z0-9_:]+|(?R)|(["\'])[^\2]*\2)\]))*)' . // var key if (preg_match('#(\$?\.?[a-z0-9_:]*(?:(?:(?:\.|->)(?:[a-z0-9_:]+|(?R))|\[(?:[a-z0-9_:]+|(?R)|(["\'])[^\2]*?\2)\]))*)' . // var key
($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='expression' ? '(\(.*)?' : '()') . // method call ($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='expression' ? '(\(.*)?' : '()') . // method call
($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='delimited_string' ? '((?:(?:[+/*%=-])(?:(?<!=)=?-?[$%][a-z0-9.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9.,]*|[+-]))*)':'()') . // simple math expressions ($curBlock==='root' || $curBlock==='function' || $curBlock==='namedparam' || $curBlock==='condition' || $curBlock==='variable' || $curBlock==='delimited_string' ? '((?:(?:[+/*%=-])(?:(?<!=)=?-?[$%][a-z0-9.[\]>_:-]+(?:\([^)]*\))?|(?<!=)=?-?[0-9.,]*|[+-]))*)':'()') . // simple math expressions
($curBlock!=='modifier' ? '((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?':'(())') . // modifiers ($curBlock!=='modifier' ? '((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').*?\5|:[^`]*))*))+)?':'(())') . // modifiers
...@@ -2253,7 +2253,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -2253,7 +2253,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} }
} }
} else { } else {
preg_match_all('#(\[|->|\.)?([a-z0-9_]+|(\\\?[\'"])[^\3]*\3)\]?#i', $key, $m); preg_match_all('#(\[|->|\.)?([a-z0-9_]+|(\\\?[\'"])[^\3]*?\3)\]?#i', $key, $m);
$i = $m[2][0]; $i = $m[2][0];
if ($i === '_parent' || $i === '_') { if ($i === '_parent' || $i === '_') {
......
...@@ -97,6 +97,16 @@ foo=baz ...@@ -97,6 +97,16 @@ foo=baz
$this->assertEquals("moobar.foobaz.", $this->dwoo->get($tpl, array())); $this->assertEquals("moobar.foobaz.", $this->dwoo->get($tpl, array()));
} }
public function testAssignmentsWithAutoEscape()
{
$cmp = new Dwoo_Compiler();
$cmp->setAutoEscape(true);
$tpl = new Dwoo_Template_String('{$foo = $bar}>{$foo}');
$tpl->forceCompilation();
$this->assertEquals(">moo", $this->dwoo->get($tpl, array('bar'=>'moo'), $cmp));
}
public function testAndOrOperatorsFollowedWithRoundBrackets() public function testAndOrOperatorsFollowedWithRoundBrackets()
{ {
$tpl = new Dwoo_Template_String('{if 1 AND (0 OR 1)}true{/if}'); $tpl = new Dwoo_Template_String('{if 1 AND (0 OR 1)}true{/if}');
...@@ -104,6 +114,14 @@ foo=baz ...@@ -104,6 +114,14 @@ foo=baz
$this->assertEquals("true", $this->dwoo->get($tpl, array())); $this->assertEquals("true", $this->dwoo->get($tpl, array()));
} }
public function testMultipleVarsWithStringKey()
{
$tpl = new Dwoo_Template_String('{$foo["bar"]}{$foo["baz"]}');
$tpl->forceCompilation();
$this->assertEquals("12", $this->dwoo->get($tpl, array('foo'=>array('bar'=>1, 'baz'=>2))));
}
} }
function Dwoo_Plugin_X_compile(Dwoo_Compiler $cmp, $text) function Dwoo_Plugin_X_compile(Dwoo_Compiler $cmp, $text)
......
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