Commit e756cf9f by seldaek

Fixed a bug when using the autoEscape feature with sub-templates (the compiled…

Fixed a bug when using the autoEscape feature with sub-templates (the compiled sub-template couldn't access the dwoo charset property, resulting in a fatal error) fixes #38 git-svn-id: svn://dwoo.org/dwoo/trunk@288 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent a1d321a8
......@@ -14,6 +14,9 @@
* Fixed a bug when accessing array indices that contain a minus sign, it
is now possible to access those using {$var[index-foo]},
{$var['index-foo']} or {$index="index-foo"} {$var[$index]}
* Fixed a bug when using the autoEscape feature with sub-templates (the
compiled sub-template couldn't access the dwoo charset property,
resulting in a fatal error)
[2009-07-18] 1.1.0
! BC Break: Dwoo::initGlobals() is only called once during the Dwoo object
......
......@@ -68,8 +68,20 @@ class Dwoo_Plugin_template extends Dwoo_Block_Plugin implements Dwoo_ICompilable
$funcName = 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'];
$search = array(
'$this->charset',
'$this->',
'$this,',
);
$replacement = array(
'$dwoo->getCharset()',
'$dwoo->',
'$dwoo,',
);
$content = str_replace($search, $replacement, $content);
$body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE.
$prepend.str_replace(array('$this->','$this,'), array('$dwoo->', '$dwoo,'), $content).$append.
$prepend.$content.$append.
Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}";
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
}
......
......@@ -505,6 +505,20 @@ bleh();
$fixCall->init('');
}
public function testSubTemplatesWithAutoEscape()
{
$tpl = new Dwoo_Template_String('{load_templates "file:'.TEST_DIRECTORY.'/resources/templates.html"}{menu $menu}{noparam}{load_templates ""}');
$tpl->forceCompilation();
$this->compiler->setAutoEscape(true);
$this->assertEquals('<ul class="level0"><li>foo</li><li>bar</li><ul class="level1"><li>baz</li><li>qux</li></ul><li>boo</li><ul class="level1"><li>far</li><ul class="level2"><li>faz</li><li>mux</li></ul></ul><li>duck</li></ul>noparamoutput'."\n",
$this->dwoo->get($tpl, array('menu'=>array('foo', 'bar'=>array('baz','qux'), 'boo'=>array('far'=>array('faz','mux')), 'duck')), $this->compiler));
$this->compiler->setAutoEscape(false);
// fixes the init call not being called (which is normal)
$fixCall = new Dwoo_Plugin_template($this->dwoo);
$fixCall->init('');
}
public function testSubTemplatesMultiInc()
{
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/templateUsage.html');
......
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