#20: Replacement of useless brackets by dot accessed vars goes wrong for string constants
Issue revisions
- closed by throhk at 2009-F-09 13:12
| Type | |
|---|---|
| State | |
| Priority | |
| Resolution | |
| Assigned to | Nobody |
| Scheduled for | 1.1.0 |
| Affected versions | |
| Affected components | Core |
| Last change | Monday 9 February 2009 13:12:16 UTC by throhk |
The function parseVar in dwoo/Dwoo/Compiler.php, class Dwoo_Compiler attempts to replace array access using brackets with the dot formatted access. This is fine as long as the bracket contains expressions or variables but goes horribly wrong for strings constants as in {{$arr["offset:20"]}}
I'd suggest to replace the following line $key = preg_replace('#[([^$'"%[.>-]+)]#', '.$1', $key);
as follows // replace useless brackets by dot accessed vars $key = preg_replace('#[([^$'"%[.>-]+)]#', '.$1', $key);
Thanks!
Jordi Boggiano at Monday 9 February 2009 13:45:06 UTC
Could you please explain what problem you experience exactly ? Because when I try to compile :
{$arr["offset:20"]}
It gets compiled to the following, which is correct :
$this->scope["arr"]["offset:20"]
Edit: That being said, the bracket handling of variable is a piece of crap and it could use an overhaul, along with the rest of the compiler.. but that's another story.
throhk at Monday 9 February 2009 14:29:07 UTC
Hi Jordi,
I'm sorry, but I was wrong about how the problem occurs. Here's a minimum example of what really happens:
The template test.tpl is not correctly parsed: <pre> {$arr["x"]} {$arr["x"]} </pre>
Using dwootest.php to invoke the template generation... <pre> <?php include 'dwoo/dwooAutoload.php';
$dwoo = new Dwoo(); $tpl = new Dwoo_Template_File("test.tpl"); $context = array("arr" => array("x"=>"y"));
echo $dwoo->output($tpl, $context); ?> </pre>
... I get: <pre> <?php ob_start(); /* template body */ ; echo $this->readVar("arr.\"x\"} {".(isset($this->scope["arr"]) ? $this->scope["arr"] : null).".\"x\"");?>
<?php /* end template body */ return $this->buffer . ob_get_clean(); ?> </pre>
It looks like the two template blocks are not recognized correctly and the second block was somehow included into the first one. Everything works fine if you use only one block.
Thanks for your time! Thomas
Jordi Boggiano at Tuesday 10 February 2009 08:23:37 UTC
Applied in changeset r250.