Commit ea7de4ee by Jordi Boggiano

properly strip enclosing quotes within ['foo'] in some edge cases

parent 44cf0559
...@@ -2094,8 +2094,8 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -2094,8 +2094,8 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$pointer += $matchedLength; $pointer += $matchedLength;
} }
// replace useless brackets by dot accessed vars // replace useless brackets by dot accessed vars and strip enclosing quotes if present
$key = preg_replace('#\[([^$%\[.>-]+)\]#', '.$1', $key); $key = preg_replace('#\[(["\']?)([^$%\[.>-]+)\1\]#', '.$2', $key);
// prevent $foo->$bar calls because it doesn't seem worth the trouble // prevent $foo->$bar calls because it doesn't seem worth the trouble
if (strpos($key, '->$') !== false) { if (strpos($key, '->$') !== false) {
......
...@@ -1249,6 +1249,9 @@ class Dwoo_Core ...@@ -1249,6 +1249,9 @@ class Dwoo_Core
while (list($k, $sep) = each($m[1])) { while (list($k, $sep) = each($m[1])) {
if ($sep === '.' || $sep === '[' || $sep === '') { if ($sep === '.' || $sep === '[' || $sep === '') {
// strip enclosing quotes if present
$m[2][$k] = preg_replace('#^(["\']?)(.*?)\1$#', '$2', $m[2][$k]);
if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) { if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) {
$data = $data[$m[2][$k]]; $data = $data[$m[2][$k]];
} else { } else {
......
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