Make WordPress Core

Changeset 61713


Ignore:
Timestamp:
02/21/2026 04:40:18 AM (8 weeks ago)
Author:
westonruter
Message:

XML-RPC: Account for parsed server URLs that do not specify host or scheme.

Developed in https://github.com/WordPress/wordpress-develop/pull/10916

Props bluefuton, tfrommen, chrispecoraro, drebbits.web, westonruter.
Fixes #64635, #40784.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/IXR/class-IXR-client.php

    r61457 r61713  
    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'] ?? '/';
  • trunk/src/wp-includes/class-wp-http-ixr-client.php

    r61594 r61713  
    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.
  • trunk/tests/phpunit/tests/xmlrpc/client.php

    r56536 r61713  
    1919
    2020    /**
     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
     28    /**
    2129     * @ticket 26947
    2230     */
     
    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}
Note: See TracChangeset for help on using the changeset viewer.