Skip to content

Commit

Permalink
Fix PHP8.1 deprecation error on null string
Browse files Browse the repository at this point in the history
Prevents E_DEPRECATED: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated
  • Loading branch information
AdrienPoupa committed Dec 19, 2022
1 parent a34ee98 commit 4a2237b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libs/plugins/modifier.truncate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
if ($length === 0) {
if ($length === 0 || $string === null) {
return '';
}
if (Smarty::$_MBSTRING) {
Expand Down
4 changes: 2 additions & 2 deletions libs/plugins/modifiercompiler.count_characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function smarty_modifiercompiler_count_characters($params)
return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
}
if (Smarty::$_MBSTRING) {
return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
return 'mb_strlen((string) ' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
return 'strlen(' . $params[ 0 ] . ')';
return 'strlen((string) ' . $params[ 0 ] . ')';
}
2 changes: 1 addition & 1 deletion libs/plugins/modifiercompiler.count_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ function smarty_modifiercompiler_count_words($params)
$params[ 0 ] . ', $tmp)';
}
// no MBString fallback
return 'str_word_count(' . $params[ 0 ] . ')';
return 'str_word_count((string) ' . $params[ 0 ] . ')';
}
4 changes: 2 additions & 2 deletions libs/plugins/modifiercompiler.lower.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
function smarty_modifiercompiler_lower($params)
{
if (Smarty::$_MBSTRING) {
return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
return 'mb_strtolower((string) ' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
return 'strtolower(' . $params[ 0 ] . ')';
return 'strtolower((string) ' . $params[ 0 ] . ')';
}
4 changes: 2 additions & 2 deletions libs/plugins/modifiercompiler.upper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
function smarty_modifiercompiler_upper($params)
{
if (Smarty::$_MBSTRING) {
return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')';
return 'mb_strtoupper((string) ' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
return 'strtoupper(' . $params[ 0 ] . ' ?? \'\')';
return 'strtoupper((string) ' . $params[ 0 ] . ' ?? \'\')';
}
2 changes: 1 addition & 1 deletion libs/plugins/outputfilter.trimwhitespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function smarty_outputfilter_trimwhitespace($source)
}
}
$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',
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/shared.escape_special_chars.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
function smarty_function_escape_special_chars($string)
{
if (!is_array($string)) {
$string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
$string = htmlspecialchars((string) $string, ENT_COMPAT, Smarty::$_CHARSET, false);
}
return $string;
}
2 changes: 1 addition & 1 deletion libs/plugins/variablefilter.htmlspecialchars.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET);
return htmlspecialchars((string) $source, ENT_QUOTES, Smarty::$_CHARSET);
}

0 comments on commit 4a2237b

Please sign in to comment.