WordPress.org

Make WordPress Core

Changeset 51606


Ignore:
Timestamp:
08/12/2021 05:48:55 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use correct comparison in do_enclose() tests.

As per the PHP manual:

If the component parameter is omitted, an associative array is returned.
If the component parameter is specified, parse_url() returns a string (or an int, in the case of PHP_URL_PORT) instead of an array. If the requested component doesn't exist within the given URL, null will be returned.

Reference: PHP Manual: parse_url(): Return Values

In this case, parse_url() is called with the PHP_URL_PATH as $component, but the returned value is subsequently checked against false.

In other words, this condition would previously always result in true and would lead to null potentially being passed to the PHP native pathinfo() function which expects a string.

On PHP 8.1, this would result in a test failure with a pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated error.

Reference: PHP Manual: pathinfo()

Follow-up to [46175].

Props jrf.
See #53635.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/doEnclose.php

    r51568 r51606  
    281281        $path = parse_url( $url, PHP_URL_PATH );
    282282
    283         if ( false !== $path ) {
     283        if ( null !== $path ) {
    284284            $extension = pathinfo( $path, PATHINFO_EXTENSION );
    285285            if ( isset( $fake_headers[ $extension ] ) ) {
Note: See TracChangeset for help on using the changeset viewer.