Database: Replace substr_compare() usage with substr() in wpdb::prepare().

This amends the previous commit to avoid a warning on PHP < 7.2.18 if haystack is an empty string:
{{{
Warning: substr_compare(): The start position cannot exceed initial string length
}}}

Follow-up to [55151], [55157].

See #52506.
Built from https://develop.svn.wordpress.org/trunk@55158


git-svn-id: http://core.svn.wordpress.org/trunk@54691 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-01-28 20:58:12 +00:00
parent d9de5c33a0
commit c588aebc84
2 changed files with 3 additions and 3 deletions

View File

@ -1562,7 +1562,7 @@ class wpdb {
$type = substr( $placeholder, -1 );
if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters
&& 0 === substr_compare( $split_query[ $key - 1 ], '%', -1, 1 )
&& '%' === substr( $split_query[ $key - 1 ], -1, 1 )
) {
/*
@ -1623,7 +1623,7 @@ class wpdb {
* Second, if "%s" has a "%" before it, even if it's unrelated (e.g. "LIKE '%%%s%%'").
*/
if ( true !== $this->allow_unsafe_unquoted_parameters
|| ( '' === $format && 0 !== substr_compare( $split_query[ $key - 1 ], '%', -1, 1 ) )
|| ( '' === $format && '%' !== substr( $split_query[ $key - 1 ], -1, 1 ) )
) {
$placeholder = "'%" . $format . "s'";
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-55157';
$wp_version = '6.2-alpha-55158';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.