Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/IXR/class-IXR-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function __construct( $server, $path = false, $port = 80, $timeout = 15 )
if (!$path) {
// Assume we have been given a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->server = $bits['host'] ?? '';
$this->port = $bits['port'] ?? 80;
$this->path = $bits['path'] ?? '/';

Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-http-ixr-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/tests/xmlrpc/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 );
}
}
Loading