From 0fd9ee91ecba2d513bd8305a9ba47165316e1e3b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Jun 2023 13:38:44 +0000 Subject: [PATCH] General: Return early from `str_ends_with()` polyfill if both haystack and needle are empty. Prior to PHP 7.0, `substr( '', -0, 0 )` returns `false` instead of an empty string, so the strict comparison further in the function did not work as expected. This commit addresses a test failure on PHP < 7.0, making the function consistently return `true` if both haystack and needle are an empty string. Follow-up to [52040], [56014], [56015]. See #58220. git-svn-id: https://develop.svn.wordpress.org/trunk@56016 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/compat.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php index 38ae725e93..d51b37cfbf 100644 --- a/src/wp-includes/compat.php +++ b/src/wp-includes/compat.php @@ -482,8 +482,8 @@ if ( ! function_exists( 'str_ends_with' ) ) { * @return bool True if `$haystack` ends with `$needle`, otherwise false. */ function str_ends_with( $haystack, $needle ) { - if ( '' === $haystack && '' !== $needle ) { - return false; + if ( '' === $haystack ) { + return '' === $needle; } $len = strlen( $needle );