Merge pull request #10798 from beerbohmdo/fix/empty-template-arguments

FIX Passing 0 as first method argument breaks template
This commit is contained in:
Guy Sartorelli 2023-06-15 11:04:08 +12:00 committed by GitHub
commit d27bf3d85c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) function CallArguments_Argument(&$res, $sub)
{ {
if (!empty($res['php'])) { if ($res['php'] !== '') {
$res['php'] .= ', '; $res['php'] .= ', ';
} }

View File

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

View File

@ -552,6 +552,40 @@ SS;
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works"); $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() public function testObjectDotArguments()
{ {
$this->assertEquals( $this->assertEquals(

View File

@ -29,6 +29,11 @@ class TestViewableData extends ViewableData implements TestOnly
return "arg1:{$arg1},arg2:{$arg2}"; 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) public function Type($arg)
{ {
return gettype($arg) . ':' . $arg; return gettype($arg) . ':' . $arg;