Skip to content

Commit 95899ee

Browse files
committed
XML-RPC: Account for parsed server URLs that do not specify host or scheme.
Developed in WordPress#10916 Props bluefuton, tfrommen, chrispecoraro, drebbits.web, westonruter. Fixes #64635, #40784. git-svn-id: https://develop.svn.wordpress.org/trunk@61713 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 97e30d9 commit 95899ee

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/wp-includes/IXR/class-IXR-client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function __construct( $server, $path = false, $port = 80, $timeout = 15 )
3030
if (!$path) {
3131
// Assume we have been given a URL instead
3232
$bits = parse_url($server);
33-
$this->server = $bits['host'];
33+
$this->server = $bits['host'] ?? '';
3434
$this->port = $bits['port'] ?? 80;
3535
$this->path = $bits['path'] ?? '/';
3636

src/wp-includes/class-wp-http-ixr-client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function __construct( $server, $path = false, $port = false, $timeout = 1
2323
if ( ! $path ) {
2424
// Assume we have been given a URL instead.
2525
$bits = parse_url( $server );
26-
$this->scheme = $bits['scheme'];
27-
$this->server = $bits['host'];
26+
$this->scheme = $bits['scheme'] ?? '';
27+
$this->server = $bits['host'] ?? '';
2828
$this->port = $bits['port'] ?? $port;
29-
$this->path = ! empty( $bits['path'] ) ? $bits['path'] : '/';
29+
$this->path = $bits['path'] ?? '/';
3030

3131
// Make absolutely sure we have a path.
3232
if ( ! $this->path ) {

tests/phpunit/tests/xmlrpc/client.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public function test_ixr_client_allows_query_strings() {
1717
$this->assertSame( '/server.php?this-is-needed=true', $client->path );
1818
}
1919

20+
/**
21+
* @ticket 64635
22+
*/
23+
public function test_ixr_client_can_handle_missing_host() {
24+
$client = new IXR_Client( '/no-host-here' );
25+
$this->assertSame( '', $client->server );
26+
}
27+
2028
/**
2129
* @ticket 26947
2230
*/
@@ -26,4 +34,33 @@ public function test_wp_ixr_client_allows_query_strings() {
2634
$this->assertFalse( $client->port );
2735
$this->assertSame( '/server.php?this-is-needed=true', $client->path );
2836
}
37+
38+
/**
39+
* @ticket 40784
40+
*/
41+
public function test_wp_ixr_client_can_handle_protocolless_urls() {
42+
$client = new WP_HTTP_IXR_Client( '//example.com/server.php' );
43+
$this->assertSame( '', $client->scheme );
44+
$this->assertSame( 'example.com', $client->server );
45+
}
46+
47+
/**
48+
* @ticket 40784
49+
*/
50+
public function test_wp_ixr_client_can_handle_relative_urls() {
51+
$client = new WP_HTTP_IXR_Client( '/server.php' );
52+
$this->assertSame( '', $client->scheme );
53+
$this->assertSame( '', $client->server );
54+
$this->assertSame( '/server.php', $client->path );
55+
}
56+
57+
/**
58+
* @ticket 40784
59+
*/
60+
public function test_wp_ixr_client_can_handle_invalid_urls() {
61+
$client = new WP_HTTP_IXR_Client( '' );
62+
$this->assertSame( '', $client->scheme );
63+
$this->assertSame( '', $client->server );
64+
$this->assertSame( '/', $client->path );
65+
}
2966
}

0 commit comments

Comments
 (0)