From fcea1a91c89b9bdaac9193d364479ccd7452903a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 28 Jan 2023 20:56:10 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55158 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wpdb.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index 22c54e75ee..1c7899a9ad 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -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'"; }