Skip to content
Open
9 changes: 9 additions & 0 deletions src/wp-includes/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,15 @@ function wp_http_validate_url( $url ) {
$host = trim( $parsed_url['host'], '.' );

if ( ! $same_host ) {
if (
function_exists( 'filter_var' )
&& defined( 'FILTER_VALIDATE_DOMAIN' )
&& defined( 'FILTER_FLAG_HOSTNAME' )
&& ! filter_var( $host, FILTER_VALIDATE_IP )
&& ! filter_var( $host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME )
) {
return false;
}
if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) {
$ip = $host;
} else {
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/http/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@
'url' => 'https://example.com:81/caniload.php',
'cb_safe_ports' => 'callback_remove_safe_ports',
),
'underscore_in_hostname' => array(

Check warning on line 569 in tests/phpunit/tests/http/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 23 space(s) between "'underscore_in_hostname'" and double arrow, but found 1.
'url' => 'https://foo_bar.example.com/',
),
);
}

Expand Down
Loading