Skip to content

Commit

Permalink
FIX Don't error if template global is null (#11331)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Aug 8, 2024
1 parent f93c9a9 commit 7b91207
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/View/SSViewer_Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public function resetLocalScope()
public function getObj($name, $arguments = [], $cache = false, $cacheName = null)
{
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
if ($on === null) {
return null;
}
return $on->obj($name, $arguments, $cache, $cacheName);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/php/View/SSViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ public function testGlobalVariablesAreEscaped()
);
}

public function testGlobalVariablesReturnNull()
{
$this->assertEquals('<p></p>', $this->render('<p>$SSViewerTest_GlobalReturnsNull</p>'));
$this->assertEquals('<p></p>', $this->render('<p>$SSViewerTest_GlobalReturnsNull.Chained.Properties</p>'));
}

public function testCoreGlobalVariableCalls()
{
$this->assertEquals(
Expand Down
9 changes: 7 additions & 2 deletions tests/php/View/SSViewerTest/TestGlobalProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static function get_template_global_variables()
'SSViewerTest_GlobalReferencedByString' => 'get_reference',
'SSViewerTest_GlobalReferencedInArray' => ['method' => 'get_reference'],

'SSViewerTest_GlobalThatTakesArguments' => ['method' => 'get_argmix', 'casting' => 'HTMLFragment']

'SSViewerTest_GlobalThatTakesArguments' => ['method' => 'get_argmix', 'casting' => 'HTMLFragment'],
'SSViewerTest_GlobalReturnsNull' => 'getNull',
];
}

Expand All @@ -43,4 +43,9 @@ public static function get_argmix()
$args = func_get_args();
return 'z' . implode(':', $args) . 'z';
}

public static function getNull()
{
return null;
}
}

0 comments on commit 7b91207

Please sign in to comment.