Skip to content

Commit

Permalink
HTTP API: Ensure value returned from 'http_allowed_safe_ports' is a…
Browse files Browse the repository at this point in the history
…n array to avoid PHP 8+ TypeError fatal error.

Adds an `is_array()` check before the `in_array()`. Why? `in_array()` requires a array for the haystack. Any other data type will cause a fatal error on PHP 8.0 or higher:

{{{
Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array
}}}

As this is a new filter, this type check properly guards to avoid the fatal error.

Follow-up to [52084].

See #54331.

git-svn-id: https://develop.svn.wordpress.org/trunk@52085 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
hellofromtonya committed Nov 9, 2021
1 parent bed3a7c commit 26c9730
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ function wp_http_validate_url( $url ) {
* @param string $url Requested URL.
*/
$allowed_ports = apply_filters( 'http_allowed_safe_ports', array( 80, 443, 8080 ), $host, $url );
if ( in_array( $port, $allowed_ports, true ) ) {
if ( is_array( $allowed_ports ) && in_array( $port, $allowed_ports, true ) ) {
return $url;
}

Expand Down

0 comments on commit 26c9730

Please sign in to comment.