Make WordPress Core

Changeset 56016


Ignore:
Timestamp:
06/24/2023 01:38:44 PM (18 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/compat.php

    r56015 r56016  
    483483     */
    484484    function str_ends_with( $haystack, $needle ) {
    485         if ( '' === $haystack && '' !== $needle ) {
    486             return false;
     485        if ( '' === $haystack ) {
     486            return '' === $needle;
    487487        }
    488488
Note: See TracChangeset for help on using the changeset viewer.