diff --git a/src/wp-includes/IXR/class-IXR-client.php b/src/wp-includes/IXR/class-IXR-client.php index 34c1f9337c461..3bf1eb9db09cc 100644 --- a/src/wp-includes/IXR/class-IXR-client.php +++ b/src/wp-includes/IXR/class-IXR-client.php @@ -1,4 +1,4 @@ -server = $bits['host']; + $this->server = $bits['host'] ?? ''; $this->port = $bits['port'] ?? 80; $this->path = $bits['path'] ?? '/'; diff --git a/src/wp-includes/class-wp-http-ixr-client.php b/src/wp-includes/class-wp-http-ixr-client.php index 71875d550fc2f..f8b0b144f8b26 100644 --- a/src/wp-includes/class-wp-http-ixr-client.php +++ b/src/wp-includes/class-wp-http-ixr-client.php @@ -23,10 +23,10 @@ public function __construct( $server, $path = false, $port = false, $timeout = 1 if ( ! $path ) { // Assume we have been given a URL instead. $bits = parse_url( $server ); - $this->scheme = $bits['scheme']; - $this->server = $bits['host']; + $this->scheme = $bits['scheme'] ?? ''; + $this->server = $bits['host'] ?? ''; $this->port = $bits['port'] ?? $port; - $this->path = ! empty( $bits['path'] ) ? $bits['path'] : '/'; + $this->path = $bits['path'] ?? '/'; // Make absolutely sure we have a path. if ( ! $this->path ) { diff --git a/tests/phpunit/tests/xmlrpc/client.php b/tests/phpunit/tests/xmlrpc/client.php index a13980c17d174..75734d8e150b7 100644 --- a/tests/phpunit/tests/xmlrpc/client.php +++ b/tests/phpunit/tests/xmlrpc/client.php @@ -17,6 +17,14 @@ public function test_ixr_client_allows_query_strings() { $this->assertSame( '/server.php?this-is-needed=true', $client->path ); } + /** + * @ticket 64635 + */ + public function test_ixr_client_can_handle_missing_host() { + $client = new IXR_Client( '/no-host-here' ); + $this->assertSame( '', $client->server ); + } + /** * @ticket 26947 */ @@ -26,4 +34,33 @@ public function test_wp_ixr_client_allows_query_strings() { $this->assertFalse( $client->port ); $this->assertSame( '/server.php?this-is-needed=true', $client->path ); } + + /** + * @ticket 40784 + */ + public function test_wp_ixr_client_can_handle_protocolless_urls() { + $client = new WP_HTTP_IXR_Client( '//example.com/server.php' ); + $this->assertSame( '', $client->scheme ); + $this->assertSame( 'example.com', $client->server ); + } + + /** + * @ticket 40784 + */ + public function test_wp_ixr_client_can_handle_relative_urls() { + $client = new WP_HTTP_IXR_Client( '/server.php' ); + $this->assertSame( '', $client->scheme ); + $this->assertSame( '', $client->server ); + $this->assertSame( '/server.php', $client->path ); + } + + /** + * @ticket 40784 + */ + public function test_wp_ixr_client_can_handle_invalid_urls() { + $client = new WP_HTTP_IXR_Client( '' ); + $this->assertSame( '', $client->scheme ); + $this->assertSame( '', $client->server ); + $this->assertSame( '/', $client->path ); + } }