mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 01:44:26 +02:00
default modifier uses empty instead of @ error suppression modifier when testing a variable
Fixes #336
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ utilies/*.php
|
||||
phpunit*
|
||||
vendor/*
|
||||
composer.lock
|
||||
/composer.phar
|
||||
|
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
- default modifier uses empty instead of @ error suppression modifier when testing a variable https://github.com/smarty-php/smarty/issues/336
|
||||
- modifier escape now triggers a E_USER_NOTICE when an unsupported escape type is used https://github.com/smarty-php/smarty/pull/649
|
||||
|
||||
## [3.1.39] - 2021-02-17
|
||||
|
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_default($params)
|
||||
function smarty_modifiercompiler_default($params, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$output = $params[ 0 ];
|
||||
if (!isset($params[ 1 ])) {
|
||||
@@ -26,7 +26,13 @@ function smarty_modifiercompiler_default($params)
|
||||
}
|
||||
array_shift($params);
|
||||
foreach ($params as $param) {
|
||||
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
|
||||
|
||||
if ($compiler->syntaxMatchesVariable($output)) {
|
||||
$output = '(empty(' . $output . ') ? ' . $param . ' : ' . $output . ')';
|
||||
} else {
|
||||
$output = '(($tmp = ' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
|
||||
}
|
||||
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
@@ -674,7 +674,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
* @param $string
|
||||
* @return bool
|
||||
*/
|
||||
private function syntaxMatchesVariable($string) {
|
||||
public function syntaxMatchesVariable($string) {
|
||||
static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/';
|
||||
return 1 === preg_match($regex_pattern, trim($string));
|
||||
}
|
||||
|
@@ -64,10 +64,10 @@ class MuteExpectedErrorsTest extends PHPUnit_Smarty
|
||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
||||
$this->smarty->fetch('default.tpl');
|
||||
|
||||
$this->assertEquals(Smarty::$_IS_WINDOWS ? 2 : 2, count($this->_errors));
|
||||
$this->assertEquals(0, count($this->_errors));
|
||||
|
||||
@filemtime('ckxladanwijicajscaslyxck');
|
||||
$this->assertEquals(Smarty::$_IS_WINDOWS ? 3 : 3, count($this->_errors));
|
||||
$this->assertEquals(1, count($this->_errors));
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
@@ -112,11 +112,11 @@ class MuteExpectedErrorsTest extends PHPUnit_Smarty
|
||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
||||
$this->smarty->fetch('default.tpl');
|
||||
|
||||
$this->assertEquals(Smarty::$_IS_WINDOWS ? 2 : 2, count($this->_errors));
|
||||
$this->assertEquals(0, count($this->_errors));
|
||||
|
||||
@filemtime('ckxladanwijicajscaslyxck');
|
||||
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
|
||||
$this->assertEquals(Smarty::$_IS_WINDOWS ? 3 : 3, count($this->_errors));
|
||||
$this->assertEquals(1, count($this->_errors));
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
@@ -110,6 +110,9 @@ class FileResourceTest extends PHPUnit_Smarty
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testGetCompiledTimestampPrepare()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('helloworld.tpl');
|
||||
@@ -142,6 +145,9 @@ class FileResourceTest extends PHPUnit_Smarty
|
||||
$this->assertTrue($tpl->mustCompile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testMustCompileTouchedSourcePrepare()
|
||||
{
|
||||
// touch to prepare next test
|
||||
|
@@ -161,7 +161,7 @@ class PhpResourceTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testIsCachedTouchedSourcePrepare()
|
||||
{
|
||||
@@ -212,6 +212,7 @@ class PhpResourceTest extends PHPUnit_Smarty
|
||||
|
||||
/**
|
||||
* test $smarty->is_cached
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testSmartyIsCachedPrepare()
|
||||
{
|
||||
|
@@ -0,0 +1 @@
|
||||
{* this is a comment *}
|
@@ -0,0 +1,7 @@
|
||||
=
|
||||
{* comment *}
|
||||
{* comment *}
|
||||
b
|
||||
{* comment *}
|
||||
{* comment *}
|
||||
=
|
@@ -0,0 +1,7 @@
|
||||
=
|
||||
a
|
||||
{* comment 1 *}
|
||||
{* comment 2 *}
|
||||
{* comment 3 *}
|
||||
b
|
||||
=
|
@@ -0,0 +1,7 @@
|
||||
=
|
||||
a
|
||||
{* comment 1 *}
|
||||
{* comment 2 *}
|
||||
{* comment 3 *}
|
||||
b
|
||||
=
|
@@ -0,0 +1,7 @@
|
||||
=
|
||||
a
|
||||
{* comment 1 *}
|
||||
{* comment 2 *}
|
||||
{* comment 3 *}
|
||||
b
|
||||
=
|
@@ -0,0 +1,7 @@
|
||||
=
|
||||
a
|
||||
{* comment 1 *}
|
||||
{* comment 2 *}
|
||||
{* comment 3 *}
|
||||
b
|
||||
=
|
@@ -0,0 +1 @@
|
||||
{* another $foo comment *}
|
@@ -0,0 +1 @@
|
||||
{* another comment *}some in between{* another comment *}
|
@@ -0,0 +1,2 @@
|
||||
{* multi line
|
||||
comment *}
|
@@ -0,0 +1 @@
|
||||
{* /* foo * / *}
|
@@ -0,0 +1,2 @@
|
||||
A{* comment *}B
|
||||
C
|
@@ -0,0 +1,3 @@
|
||||
D{* comment *}
|
||||
{* comment *}E
|
||||
F
|
@@ -0,0 +1,2 @@
|
||||
G{* multi
|
||||
line *}H
|
@@ -0,0 +1,3 @@
|
||||
I{* multi
|
||||
line *}
|
||||
J
|
@@ -20,6 +20,9 @@ class PluginFunctionHtmlImageTest extends PHPUnit_Smarty
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testFoo()
|
||||
{
|
||||
// TODO: UnitTests for {html_image}
|
||||
|
@@ -291,6 +291,9 @@ class ScopeTest extends PHPUnit_Smarty
|
||||
'no smarty', $i ++,),);
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testFunctionScope()
|
||||
{
|
||||
$this->smarty->assign('scope', 'none');
|
||||
|
Reference in New Issue
Block a user