From d9de5c33a0f7b96d00bc148610ecec4362d1ec23 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 28 Jan 2023 13:48:20 +0000 Subject: [PATCH] Database: Replace `str_ends_with()` usage in `wpdb::prepare()`. This avoids a fatal error if the file is included directly outside of WordPress core, e.g. by HyperDB. While WordPress core does include a polyfill function, it is not directly loaded in the `wpdb` class. This commit replaces the `str_ends_with()` calls with `substr_compare()` for now. Follow-up to [55151]. Props Otto42. See #52506. Built from https://develop.svn.wordpress.org/trunk@55157 git-svn-id: http://core.svn.wordpress.org/trunk@54690 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wpdb.php | 8 ++++++-- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wpdb.php b/wp-includes/class-wpdb.php index b615627293..22c54e75ee 100644 --- a/wp-includes/class-wpdb.php +++ b/wp-includes/class-wpdb.php @@ -1561,7 +1561,9 @@ class wpdb { $format = substr( $placeholder, 1, -1 ); $type = substr( $placeholder, -1 ); - if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters && str_ends_with( $split_query[ $key - 1 ], '%' ) ) { + if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters + && 0 === substr_compare( $split_query[ $key - 1 ], '%', -1, 1 ) + ) { /* * Before WP 6.2 the "force floats to be locale-unaware" RegEx didn't @@ -1620,7 +1622,9 @@ class wpdb { * First, "numbered or formatted string placeholders (eg, %1$s, %5s)". * Second, if "%s" has a "%" before it, even if it's unrelated (e.g. "LIKE '%%%s%%'"). */ - if ( true !== $this->allow_unsafe_unquoted_parameters || ( '' === $format && ! str_ends_with( $split_query[ $key - 1 ], '%' ) ) ) { + if ( true !== $this->allow_unsafe_unquoted_parameters + || ( '' === $format && 0 !== substr_compare( $split_query[ $key - 1 ], '%', -1, 1 ) ) + ) { $placeholder = "'%" . $format . "s'"; } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 00c927ae83..47c8298d3d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55156'; +$wp_version = '6.2-alpha-55157'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.