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
This commit is contained in:
Sergey Biryukov
2023-06-24 13:38:44 +00:00
parent 0783feeeca
commit 0fd9ee91ec

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