mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
Formatting: Handle non-scalar types passed to sanitize_key().
`sanitize_key()` expects a string type for the given `key`. Passing any other data type to `strtolower()` can result in `E_WARNING: strtolower() expects parameter 1 to be string, array given`. A check is added that if the key is not a string, the key is set to an empty string. For performance, the additional string processing is skipped if the key is an empty string. This change maintains backwards-compatibility for valid string keys while fixing the bug of non-string keys. Props costdev, dd32. Fixes #54160. git-svn-id: https://develop.svn.wordpress.org/trunk@52292 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2137,8 +2137,15 @@ function sanitize_user( $username, $strict = false ) {
|
||||
*/
|
||||
function sanitize_key( $key ) {
|
||||
$raw_key = $key;
|
||||
$key = strtolower( $key );
|
||||
$key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
|
||||
|
||||
if ( ! is_string( $key ) ) {
|
||||
$key = '';
|
||||
}
|
||||
|
||||
if ( '' !== $key ) {
|
||||
$key = strtolower( $key );
|
||||
$key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a sanitized key string.
|
||||
|
||||
Reference in New Issue
Block a user