Skip to content

Commit

Permalink
Fix error with null variable
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbrault committed Jan 15, 2014
1 parent 086a314 commit 322eb06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Nelmio/Alice/Loader/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private function process($data, array $variables)

// replace references to other variables in the same object
$args = preg_replace_callback('{\{?\$([a-z0-9_]+)\}?}i', function ($match) use ($variables) {
if (isset($variables[$match[1]])) {
if (array_key_exists($match[1], $variables)) {
return '$variables['.var_export($match[1], true).']';
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Nelmio/Alice/Loader/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,22 @@ public function testCustomNonexistantSetFunction()
)
);
}

public function testNullVariable()
{
$loader = new Base('en_US', array(new FakerProvider));
$loader->load(array(
self::USER => array(
'user' => array(
'username' => '0%? adrien',
'fullname' => '<noop($username)>',
),
),
));

$this->assertNull($loader->getReference('user')->username);
$this->assertNull($loader->getReference('user')->fullname);
}
}

class FakerProvider
Expand Down

0 comments on commit 322eb06

Please sign in to comment.