Skip to content

Commit

Permalink
Tests: Use correct comparison in do_enclose() tests.
Browse files Browse the repository at this point in the history
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: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues 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: [https://www.php.net/manual/en/function.pathinfo.php PHP Manual: pathinfo()]

Follow-up to [46175].

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51606 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Aug 12, 2021
1 parent 2985e90 commit 6406dba
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/phpunit/tests/functions/doEnclose.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function fake_http_request( $false, $arguments, $url ) {

$path = parse_url( $url, PHP_URL_PATH );

if ( false !== $path ) {
if ( null !== $path ) {
$extension = pathinfo( $path, PATHINFO_EXTENSION );
if ( isset( $fake_headers[ $extension ] ) ) {
return $fake_headers[ $extension ];
Expand Down

0 comments on commit 6406dba

Please sign in to comment.