Update StringUtils.php
This commit is contained in:
parent
36948bb382
commit
56ed71c7d2
@ -45,8 +45,8 @@ class StringUtils
|
|||||||
return hash_equals($knownString, $userInput);
|
return hash_equals($knownString, $userInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
$knownLen = strlen($knownString);
|
$knownLen = self::safeStrlen($knownString);
|
||||||
$userLen = strlen($userInput);
|
$userLen = self::safeStrlen($userInput);
|
||||||
|
|
||||||
// Extend the known string to avoid uninitialized string offsets
|
// Extend the known string to avoid uninitialized string offsets
|
||||||
$knownString .= $userInput;
|
$knownString .= $userInput;
|
||||||
@ -63,4 +63,18 @@ class StringUtils
|
|||||||
// They are only identical strings if $result is exactly 0...
|
// They are only identical strings if $result is exactly 0...
|
||||||
return 0 === $result;
|
return 0 === $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of bytes in a string
|
||||||
|
*
|
||||||
|
* @param string $string The string whose length we wish to obtain
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function safeStrlen($string)
|
||||||
|
{
|
||||||
|
if (function_exists('mb_strlen')) {
|
||||||
|
return mb_strlen($string, '8bit');
|
||||||
|
}
|
||||||
|
return strlen($string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user