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.
Built from https://develop.svn.wordpress.org/trunk@56016


git-svn-id: http://core.svn.wordpress.org/trunk@55528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-06-24 13:40:21 +00:00
parent 848e8cbaec
commit e0ffbee0aa
2 changed files with 3 additions and 3 deletions

View File

@ -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 );

View File

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