Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP8.1 deprecation warnings on null string in modifiers #834

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand All @@ -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)
- 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
Expand Down
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);
}