FIX Don't error if template global is null (#11331)

This commit is contained in:
Guy Sartorelli 2024-08-09 09:27:38 +12:00 committed by GitHub
parent f93c9a9a34
commit 7b91207c12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -177,6 +177,9 @@ class SSViewer_Scope
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);
}

View File

@ -364,6 +364,12 @@ SS;
);
}
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(

View File

@ -18,8 +18,8 @@ class TestGlobalProvider implements TemplateGlobalProvider, TestOnly
'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',
];
}
@ -43,4 +43,9 @@ class TestGlobalProvider implements TemplateGlobalProvider, TestOnly
$args = func_get_args();
return 'z' . implode(':', $args) . 'z';
}
public static function getNull()
{
return null;
}
}