Make WordPress Core

Ticket #34335: 34335.diff

File 34335.diff, 3.0 KB (added by stephenharris, 8 years ago)
  • src/wp-includes/class-oembed.php

    diff --git src/wp-includes/class-oembed.php src/wp-includes/class-oembed.php
    index 9790d26..732f57a 100644
    class WP_oEmbed { 
    457457
    458458                $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
    459459                $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
    460                 $provider = add_query_arg( 'url', urlencode($url), $provider );
     460
     461                //Only add the 'url' query variable if it is not already present:
     462                //@see https://core.trac.wordpress.org/ticket/34335
     463                $provider_parts = parse_url( $provider );
     464                parse_str( $provider_parts['query'], $query_variables );
     465                if ( ! isset ( $query_variables['url'] ) ) {
     466                        $provider = add_query_arg( 'url', urlencode( $url ), $provider );
     467                }
    461468
    462469                /**
    463470                 * Filters the oEmbed URL to be fetched.
  • tests/phpunit/tests/oembed/wpOembed.php

    diff --git tests/phpunit/tests/oembed/wpOembed.php tests/phpunit/tests/oembed/wpOembed.php
    index b7e6887..01d5ea6 100644
    class Tests_WP_oEmbed extends WP_UnitTestCase { 
    6969                $this->assertTrue( false !== $this->pre_oembed_result_filtered );
    7070                $this->assertFalse( $actual );
    7171        }
     72
     73        /**
     74         * @ticket https://core.trac.wordpress.org/ticket/34335
     75         */
     76        public function test_fetch_of_provider_with_url() {
     77
     78                $this->_provider_url = null;
     79                add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 );
     80
     81                //Discovered endpoint contains an url query variable, this should be used instead of the passed url
     82                $this->oembed->fetch( 'discovered.com/provider/endpoint?url=discovered.com/post', 'original.url', array(
     83                        'discovered' => true
     84                ) );
     85
     86                remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) );
     87
     88                //Confirm that
     89                $provider_parts = parse_url( $this->_provider_url );
     90                parse_str( $provider_parts['query'], $query_variables );
     91                $this->assertEquals( 'discovered.com/post', $query_variables['url'] );
     92        }
     93
     94        /**
     95         * @ticket https://core.trac.wordpress.org/ticket/34335
     96         */
     97        public function test_fetch_of_provider_without_url() {
     98
     99                $this->_provider_url = null;
     100                add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 );
     101
     102                //Discovered endpoint does not contain an url query variable, we should insert the passed url
     103                $this->oembed->fetch( 'discovered.com/provider/endpoint', 'original.url', array(
     104                        'discovered' => true
     105                ) );
     106
     107                remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) );
     108
     109                //Confirm that
     110                $provider_parts = parse_url( $this->_provider_url );
     111                parse_str( $provider_parts['query'], $query_variables );
     112                $this->assertEquals( 'original.url', $query_variables['url'] );
     113        }
     114
     115        public function _http_mock_response( $response,  $request_args, $request_url ) {
     116                $this->_provider_url = $request_url;
     117                return array(
     118                        'headers'  => array(),
     119                        'body'     => '',
     120                        'response' => array(
     121                                'code'    => 200,
     122                                'message' => '',
     123                        ),
     124                        'cookies'  => array(),
     125                        'filename' => false,
     126                );
     127        }
    72128}