PHP 8.1 deprecation warnings on null strings in modifiers (#834)

This commit is contained in:
Adrien Poupa
2023-01-16 18:24:23 -05:00
committed by GitHub
parent 73ff8fd3d0
commit 5988116c81
9 changed files with 14 additions and 13 deletions

View File

@@ -10,7 +10,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 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 - `$smarty->muteUndefinedOrNullWarnings()` now treats undefined vars and array access of a null or false variables
equivalent across all supported PHP versions 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 ## [4.3.0] - 2022-11-22
### Added ### Added
@@ -32,7 +34,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) - 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) - 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 ## [4.2.1] - 2022-09-14
### Security ### Security

View File

@@ -26,7 +26,7 @@
*/ */
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{ {
if ($length === 0) { if ($length === 0 || $string === null) {
return ''; return '';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {

View File

@@ -25,8 +25,8 @@ function smarty_modifiercompiler_count_characters($params)
return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)'; return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
} }
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strlen((string) ' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strlen(' . $params[ 0 ] . ')'; return 'strlen((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -27,5 +27,5 @@ function smarty_modifiercompiler_count_words($params)
$params[ 0 ] . ', $tmp)'; $params[ 0 ] . ', $tmp)';
} }
// no MBString fallback // no MBString fallback
return 'str_word_count(' . $params[ 0 ] . ')'; return 'str_word_count((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -22,8 +22,8 @@
function smarty_modifiercompiler_lower($params) function smarty_modifiercompiler_lower($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtolower((string) ' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtolower(' . $params[ 0 ] . ')'; return 'strtolower((string) ' . $params[ 0 ] . ')';
} }

View File

@@ -21,8 +21,8 @@
function smarty_modifiercompiler_upper($params) function smarty_modifiercompiler_upper($params)
{ {
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')'; return 'mb_strtoupper((string) ' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')';
} }
// no MBString fallback // no MBString fallback
return 'strtoupper(' . $params[ 0 ] . ' ?? \'\')'; return 'strtoupper((string) ' . $params[ 0 ] . ' ?? \'\')';
} }

View File

@@ -62,7 +62,7 @@ function smarty_outputfilter_trimwhitespace($source)
} }
} }
$expressions = array(// replace multiple spaces between tags by a single space $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', '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove spaces between attributes (but not in attribute values!) // remove spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',

View File

@@ -20,7 +20,7 @@
function smarty_function_escape_special_chars($string) function smarty_function_escape_special_chars($string)
{ {
if (!is_array($string)) { if (!is_array($string)) {
$string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); $string = htmlspecialchars((string) $string, ENT_COMPAT, Smarty::$_CHARSET, false);
} }
return $string; return $string;
} }

View File

@@ -15,5 +15,5 @@
*/ */
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template) function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{ {
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET); return htmlspecialchars((string) $source, ENT_QUOTES, Smarty::$_CHARSET);
} }