Code Modernization: Return an empty string from wpdb::_real_escape() if a non-scalar value is passed.

This avoids a fatal error on PHP 8 caused by passing a non-string value to ` mysqli_real_escape_string()`, and maintains the current behaviour.

See #50913, #50639.
Built from https://develop.svn.wordpress.org/trunk@48980


git-svn-id: http://core.svn.wordpress.org/trunk@48742 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-09-16 01:48:10 +00:00
parent b37e0cec1b
commit 9734ed5673
2 changed files with 5 additions and 1 deletions

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-48979';
$wp_version = '5.6-alpha-48980';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -1159,6 +1159,10 @@ class wpdb {
* @return string Escaped string.
*/
function _real_escape( $string ) {
if ( ! is_scalar( $string ) && ! is_null( $string ) ) {
return '';
}
if ( $this->dbh ) {
if ( $this->use_mysqli ) {
$escaped = mysqli_real_escape_string( $this->dbh, $string );