FIX Passing 0 as first argument breaks template

Replace !empty with explicit string test
Added test for falseish first parameter arguments
This commit is contained in:
dominik 2023-06-06 12:32:43 +02:00
parent fd57f06755
commit face94371e
4 changed files with 41 additions and 2 deletions

View File

@ -242,7 +242,7 @@ class SSTemplateParser extends Parser implements TemplateParser
*/
function CallArguments_Argument(&$res, $sub)
{
if (!empty($res['php'])) {
if ($res['php'] !== '') {
$res['php'] .= ', ';
}

View File

@ -567,7 +567,7 @@ class SSTemplateParser extends Parser implements TemplateParser
*/
function CallArguments_Argument(&$res, $sub)
{
if (!empty($res['php'])) {
if ($res['php'] !== '') {
$res['php'] .= ', ';
}

View File

@ -552,6 +552,40 @@ SS;
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works");
}
public function provideArgumentTypes()
{
return [
[
'arg1:0,arg2:"string",arg3:true',
'$methodWithTypedArguments(0, "string", true).RAW',
],
[
'arg1:false,arg2:"string",arg3:true',
'$methodWithTypedArguments(false, "string", true).RAW',
],
[
'arg1:null,arg2:"string",arg3:true',
'$methodWithTypedArguments(null, "string", true).RAW',
],
[
'arg1:"",arg2:"string",arg3:true',
'$methodWithTypedArguments("", "string", true).RAW',
],
[
'arg1:0,arg2:1,arg3:2',
'$methodWithTypedArguments(0, 1, 2).RAW',
],
];
}
/**
* @dataProvider provideArgumentTypes
*/
public function testArgumentTypes(string $expected, string $template)
{
$this->assertEquals($expected, $this->render($template, new TestViewableData()));
}
public function testObjectDotArguments()
{
$this->assertEquals(

View File

@ -29,6 +29,11 @@ class TestViewableData extends ViewableData implements TestOnly
return "arg1:{$arg1},arg2:{$arg2}";
}
public function methodWithTypedArguments($arg1, $arg2, $arg3)
{
return 'arg1:' . json_encode($arg1) . ',arg2:' . json_encode($arg2) . ',arg3:' . json_encode($arg3);
}
public function Type($arg)
{
return gettype($arg) . ':' . $arg;