Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#26947 closed defect (bug) (fixed)

IXR_Client strips query string from server URL

Reported by: cfinke's profile cfinke Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.9
Component: XML-RPC Keywords:
Focuses: Cc:

Description

IXR_Client (and WP_HTTP_IXR_Client) has the option to pass the entire server URL as the first argument to the constructor, and it will parse out the path from the host:

if (!$path) {
            // Assume we have been given a URL instead

Example:

$ixr_client = new IXR_Client( 'http://www.example.com/path/' );
var_dump( $ixr_client );

Output:

object(IXR_Client)#35 (10) {
  ["server"]=>
  string(15) "www.example.com"
  ["port"]=>
  int(80)
  ["path"]=>
  string(6) "/path/"
  ["useragent"]=>
  string(31) "The Incutio XML-RPC PHP Library"
  ["response"]=>
  NULL
  ["message"]=>
  bool(false)
  ["debug"]=>
  bool(false)
  ["timeout"]=>
  int(15)
  ["headers"]=>
  array(0) {
  }
  ["error"]=>
  bool(false)
}

However, if you send a URL that has a query string, IXR_Client ignores it:

$ixr_client = new IXR_Client( 'http://www.example.com/path/?param=arg' );
var_dump( $ixr_client );

Output (identical to the output above):

object(IXR_Client)#35 (10) {
  ["server"]=>
  string(15) "www.example.com"
  ["port"]=>
  int(80)
  ["path"]=>
  string(6) "/path/"
  ["useragent"]=>
  string(31) "The Incutio XML-RPC PHP Library"
  ["response"]=>
  NULL
  ["message"]=>
  bool(false)
  ["debug"]=>
  bool(false)
  ["timeout"]=>
  int(15)
  ["headers"]=>
  array(0) {
  }
  ["error"]=>
  bool(false)
}

I don't believe this actually affects WordPress core, but it might cause problems for any plugins using IXR_Client or WP_HTTP_IXR_Client.

I've attached a patch that fixes this bug in both IXR_Client and WP_HTTP_IXR_Client and results in the same client state if the full URL (with query string) is passed in the first argument or if a path (with query string) is passed in the second argument.

Attachments (1)

ixr_query_string_patch.diff (1009 bytes) - added by cfinke 11 years ago.
Allow query strings to be included in the $server argument to IXR_Client and WP_HTTP_IXR_Client.

Download all attachments as: .zip

Change History (4)

@cfinke
11 years ago

Allow query strings to be included in the $server argument to IXR_Client and WP_HTTP_IXR_Client.

#1 @nacin
11 years ago

  • Milestone changed from Awaiting Review to 3.9

So your endpoint actually requires a query string? Interesting. I've used this client for a few projects before and never came across that.

This looks good to me. Adding it to 'path' seems to be proper. The reason why the host and path are split is so the host can be used in headers and in opening a socket connection (for IXR_Client — WP_HTTP handles this differently). POSTing to a path with a query string is perfectly valid.

I wonder if there's a decent way to unit test this.

#2 @cfinke
11 years ago

So your endpoint actually requires a query string?

Yes.

I wonder if there's a decent way to unit test this.

If you're confident in the current tests for the library, checking that the state of an object instantiated with the full URL + path + query string as the first argument matches the state of an object where the path + query string was passed as the second argument should do.

#3 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27552:

Allow query strings for servers in IXR_Client and WP_HTTP_IXR_Client.

props cfinke.
fixes #26947.

Note: See TracTickets for help on using tickets.