Make WordPress Core

Changeset 55158


Ignore:
Timestamp:
01/28/2023 08:56:10 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Database: Replace substr_compare() usage with substr() in wpdb::prepare().

This amends the previous commit to avoid a warning on PHP < 7.2.18 if haystack is an empty string:

Warning: substr_compare(): The start position cannot exceed initial string length

Follow-up to [55151], [55157].

See #52506.

File:
1 edited

Legend:

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

    r55157 r55158  
    15631563
    15641564            if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters
    1565                 && 0 === substr_compare( $split_query[ $key - 1 ], '%', -1, 1 )
     1565                && '%' === substr( $split_query[ $key - 1 ], -1, 1 )
    15661566            ) {
    15671567
     
    16241624                     */
    16251625                    if ( true !== $this->allow_unsafe_unquoted_parameters
    1626                         || ( '' === $format && 0 !== substr_compare( $split_query[ $key - 1 ], '%', -1, 1 ) )
     1626                        || ( '' === $format && '%' !== substr( $split_query[ $key - 1 ], -1, 1 ) )
    16271627                    ) {
    16281628                        $placeholder = "'%" . $format . "s'";
Note: See TracChangeset for help on using the changeset viewer.