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

Fixed "passing null to parameter" in Mage_Core_Helper_String #3341

Merged
merged 1 commit into from
Jun 21, 2023
Merged
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
30 changes: 23 additions & 7 deletions app/code/core/Mage/Core/Helper/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Mage_Core_Helper_String extends Mage_Core_Helper_Abstract
public function truncate($string, $length = 80, $etc = '...', &$remainder = '', $breakWords = true)
{
$remainder = '';
if ($length == 0) {
if (is_null($string) || $length == 0) {
return '';
}

Expand Down Expand Up @@ -75,7 +75,7 @@ public function truncate($string, $length = 80, $etc = '...', &$remainder = '',
*/
public function strlen($string)
{
return iconv_strlen($string, self::ICONV_CHARSET);
return is_null($string) ? 0 : iconv_strlen($string, self::ICONV_CHARSET);
}

/**
Expand All @@ -88,6 +88,9 @@ public function strlen($string)
*/
public function substr($string, $offset, $length = null)
{
if (is_null($string)) {
return '';
}
$string = $this->cleanString($string);
if (is_null($length)) {
$length = $this->strlen($string) - $offset;
Expand Down Expand Up @@ -246,6 +249,9 @@ public function str_split($str, $length = 1, $keepWords = false, $trim = false,
*/
public function splitWords($str, $uniqueOnly = false, $maxWordLength = 0, $wordSeparatorRegexp = '\s')
{
if (is_null($str)) {
return [];
}
$result = [];
$split = preg_split('#' . $wordSeparatorRegexp . '#siu', $str, -1, PREG_SPLIT_NO_EMPTY);
foreach ($split as $word) {
Expand All @@ -269,8 +275,12 @@ public function splitWords($str, $uniqueOnly = false, $maxWordLength = 0, $wordS
*/
public function cleanString($string)
{
return '"libiconv"' == ICONV_IMPL ?
iconv(self::ICONV_CHARSET, self::ICONV_CHARSET . '//IGNORE', $string) : $string;
if (is_null($string)) {
return '';
}
return '"libiconv"' == ICONV_IMPL
? iconv(self::ICONV_CHARSET, self::ICONV_CHARSET . '//IGNORE', $string)
: $string;
}

/**
Expand All @@ -279,11 +289,11 @@ public function cleanString($string)
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int
* @return int|false
*/
public function strpos($haystack, $needle, $offset = null)
public function strpos($haystack, $needle, $offset = 0)
{
return iconv_strpos($haystack, $needle, $offset, self::ICONV_CHARSET);
return iconv_strpos((string) $haystack, (string) $needle, $offset, self::ICONV_CHARSET);
}

/**
Expand Down Expand Up @@ -315,6 +325,9 @@ public function ksortMultibyte(array &$sort)
*/
public function parseQueryStr($str)
{
if (is_null($str)) {
return [];
}
$argSeparator = '&';
$result = [];
$partsQueryStr = explode($argSeparator, $str);
Expand Down Expand Up @@ -510,6 +523,9 @@ public function uniOrd($c)
*/
public function unserialize($str)
{
if (is_null($str)) {
return null;
}
$reader = new Unserialize_Reader_ArrValue('data');
$prevChar = null;
for ($i = 0; $i < strlen($str); $i++) {
Expand Down
Loading