diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c95da5..1e2ea3a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `$smarty->muteUndefinedOrNullWarnings()` now also mutes PHP7 notices for undefined array indexes [#736](https://github.com/smarty-php/smarty/issues/736) - `$smarty->muteUndefinedOrNullWarnings()` now treats undefined vars and array access of a null or false variables equivalent across all supported PHP versions -- `$smarty->muteUndefinedOrNullWarnings()` now allows dereferencing of non-objects accross all supported PHP versions [#831](https://github.com/smarty-php/smarty/issues/831) +- `$smarty->muteUndefinedOrNullWarnings()` now allows dereferencing of non-objects across all supported PHP versions [#831](https://github.com/smarty-php/smarty/issues/831) +- PHP 8.1 deprecation warnings on null strings in modifiers [#834](https://github.com/smarty-php/smarty/pull/834) + ## [4.3.0] - 2022-11-22 ### Added @@ -43,7 +45,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586) - Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581) - ## [4.2.1] - 2022-09-14 ### Security diff --git a/src/Compile/Modifier/LowerModifierCompiler.php b/src/Compile/Modifier/LowerModifierCompiler.php index 7b95ffc6..4186b1ec 100644 --- a/src/Compile/Modifier/LowerModifierCompiler.php +++ b/src/Compile/Modifier/LowerModifierCompiler.php @@ -14,7 +14,7 @@ namespace Smarty\Compile\Modifier; class LowerModifierCompiler extends Base { public function compile($params, \Smarty\Compiler\Template $compiler) { - return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')'; + return 'mb_strtolower((string) ' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')'; } } \ No newline at end of file diff --git a/src/Compile/Modifier/UpperModifierCompiler.php b/src/Compile/Modifier/UpperModifierCompiler.php index c658fc5e..9bef41ff 100644 --- a/src/Compile/Modifier/UpperModifierCompiler.php +++ b/src/Compile/Modifier/UpperModifierCompiler.php @@ -13,7 +13,7 @@ namespace Smarty\Compile\Modifier; class UpperModifierCompiler extends Base { public function compile($params, \Smarty\Compiler\Template $compiler) { - return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')'; + return 'mb_strtoupper((string) ' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')'; } } diff --git a/src/Extension/DefaultExtension.php b/src/Extension/DefaultExtension.php index 75410a6d..569b4e86 100644 --- a/src/Extension/DefaultExtension.php +++ b/src/Extension/DefaultExtension.php @@ -651,7 +651,7 @@ class DefaultExtension extends Base { */ public function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { - if ($length === 0) { + if ($length === 0 || $string === null) { return ''; } if (mb_strlen($string, \Smarty\Smarty::$_CHARSET) > $length) { diff --git a/src/Filter/Output/TrimWhitespace.php b/src/Filter/Output/TrimWhitespace.php index 199d097f..5803725e 100644 --- a/src/Filter/Output/TrimWhitespace.php +++ b/src/Filter/Output/TrimWhitespace.php @@ -62,7 +62,7 @@ class TrimWhitespace implements \Smarty\Filter\FilterInterface { } } $expressions = array(// replace multiple spaces between tags by a single space - // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements + // can't remove them entirely, because that might break poorly implemented CSS display:inline-block elements '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', // remove spaces between attributes (but not in attribute values!) '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', diff --git a/src/functions.php b/src/functions.php index b647335b..5396ffcb 100644 --- a/src/functions.php +++ b/src/functions.php @@ -183,7 +183,7 @@ function smarty_mb_str_replace($search, $replace, $subject, &$count = 0) function smarty_function_escape_special_chars($string) { if (!is_array($string)) { - $string = htmlspecialchars($string, ENT_COMPAT, \Smarty\Smarty::$_CHARSET, false); + $string = htmlspecialchars((string) $string, ENT_COMPAT, \Smarty\Smarty::$_CHARSET, false); } return $string; } diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/nocache_lib.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/nocache_lib.tpl deleted file mode 100644 index 8602140e..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/nocache_lib.tpl +++ /dev/null @@ -1,6 +0,0 @@ -{function 'nocache1' default1='d1' default2='d2'} - default1={$default1} - default2={$default1 nocache} - p1={$p1} - p2={$p2 nocache} -{/function} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test0.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test0.tpl deleted file mode 100644 index ae27c661..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test0.tpl +++ /dev/null @@ -1,4 +0,0 @@ -Test 1 -
-{include 'test7.tpl' compile_id = 4} - diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test1.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test1.tpl deleted file mode 100644 index c8992cca..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test1.tpl +++ /dev/null @@ -1,7 +0,0 @@ -Test 1 -
-{include 'test7.tpl' compile_id = $id} -{include 'test6.tpl'} -{include file="test2.tpl"} -{include 'test6.tpl'} - diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test2.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test2.tpl deleted file mode 100644 index 9b526949..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test2.tpl +++ /dev/null @@ -1,3 +0,0 @@ -Test 2 -
-{include file="test3.tpl" compile_id=4} diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test3.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test3.tpl deleted file mode 100644 index c4ca3221..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test3.tpl +++ /dev/null @@ -1,4 +0,0 @@ -Test 3 {call name='f' nocache} -
-{include file="test4.tpl" compile_id=9} -{include file="test5.tpl" cache_id="7"} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test4.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test4.tpl deleted file mode 100644 index 13b0cbbb..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test4.tpl +++ /dev/null @@ -1,3 +0,0 @@ -Test 4 -
-{include file="test5.tpl" cache_id="7"} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test5.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test5.tpl deleted file mode 100644 index 0a65c4c8..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test5.tpl +++ /dev/null @@ -1,4 +0,0 @@ -test 5 -
- -{call 'f'} diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test6.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test6.tpl deleted file mode 100644 index d7379f81..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test6.tpl +++ /dev/null @@ -1,8 +0,0 @@ -test 6 -
-{function name='f'} -
- function f {$id} {$foo} -
-{/function} -
Time 6 = {$t6}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test7.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test7.tpl deleted file mode 100644 index cc378526..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/CachingTests/test7.tpl +++ /dev/null @@ -1,2 +0,0 @@ -test 7 -
extern \ No newline at end of file