Skip to content

Commit

Permalink
* [Bots/Scripting] Fixed an issue in bot behavior scripts where tempo…
Browse files Browse the repository at this point in the history
…rary variables could overwrite placeholders of the same name.

Fixes #842
  • Loading branch information
jstanden committed Dec 29, 2018
1 parent 2a46839 commit 79d0122
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 1 addition & 5 deletions libs/devblocks/api/services/template_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,7 @@ public function exists($name) {
return isset($this->_dictionary[$name]);
}

public function delegateUndefinedVariable($name, &$context) {
$this->$name;

$context = array_merge($context, $this->_dictionary);

public function delegateUndefinedVariable($name) {
return $this->get($name);
}

Expand Down
4 changes: 2 additions & 2 deletions libs/devblocks/libs/Twig/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,10 @@ public function getUndefinedVariableCallbacks() {
* @param string $name The undefined variable
* @return mixed
*/
public function getUndefinedVariable($name, &$context)
public function getUndefinedVariable($name)
{
foreach ($this->variableCallbacks as $callback) {
if(false !== ($value = $callback($name, $context)))
if(false !== ($value = $callback($name)))
return $value;
}

Expand Down
17 changes: 14 additions & 3 deletions libs/devblocks/libs/Twig/Node/Expression/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ public function compile(Twig_Compiler $compiler)
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
$compiler
->raw('(')
->raw('array_key_exists(')
->repr($name)
->raw(', $context)')
->raw(' || ')
->raw('!is_null(')
->raw('$this->env->getUndefinedVariable(')
->repr($name)
->raw('))')
->raw(')')
;
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
Expand All @@ -56,7 +67,7 @@ public function compile(Twig_Compiler $compiler)
//->raw('null)')
->raw('$this->env->getUndefinedVariable(')
->string($name)
->raw(', $context))')
->raw('))')
;
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
Expand All @@ -76,7 +87,7 @@ public function compile(Twig_Compiler $compiler)
//->raw('null)')
->raw('$this->env->getUndefinedVariable(')
->string($name)
->raw(', $context))')
->raw('))')
;
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
Expand Down
2 changes: 1 addition & 1 deletion libs/devblocks/libs/Twig/Node/SetTemp.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function compile(Twig_Compiler $compiler)
//->raw("_ = null; }\n")
->raw("_ = \$this->env->getUndefinedVariable('")
->raw($name)
->raw("', \$context); }\n")
->raw("'); }\n")
;
}
}

0 comments on commit 79d0122

Please sign in to comment.