Ticket #34335: 34335.2.diff
File 34335.2.diff, 3.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-oembed.php
diff --git src/wp-includes/class-oembed.php src/wp-includes/class-oembed.php index 052a215..19d2f82 100644
class WP_oEmbed { 464 464 465 465 $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); 466 466 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); 467 $provider = add_query_arg( 'url', urlencode($url), $provider ); 467 468 /* 469 * Only add the 'url' query variable if it is not already present. 470 * 471 * @see https://core.trac.wordpress.org/ticket/34335 472 */ 473 $url_query = parse_url( $provider, PHP_URL_QUERY ); 474 parse_str( $url_query, $query_variables ); 475 476 if ( ! isset ( $query_variables['url'] ) ) { 477 $provider = add_query_arg( 'url', urlencode( $url ), $provider ); 478 } 468 479 469 480 /** 470 481 * 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..a1fecd4 100644
class Tests_WP_oEmbed extends WP_UnitTestCase { 11 11 12 12 public $pre_oembed_result_filtered = false; 13 13 14 /** 15 * @var string 16 */ 17 protected $_provider_url = null; 18 14 19 public function setUp() { 15 20 parent::setUp(); 16 21 … … class Tests_WP_oEmbed extends WP_UnitTestCase { 18 23 $this->oembed = _wp_oembed_get_object(); 19 24 20 25 $this->pre_oembed_result_filtered = false; 26 $this->_provider_url = null; 21 27 } 22 28 23 29 public function _filter_pre_oembed_result( $result ) { … … class Tests_WP_oEmbed extends WP_UnitTestCase { 69 75 $this->assertTrue( false !== $this->pre_oembed_result_filtered ); 70 76 $this->assertFalse( $actual ); 71 77 } 78 79 /** 80 * @ticket 34335 81 */ 82 public function test_fetch_of_provider_with_url() { 83 add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 ); 84 85 //Discovered endpoint contains an url query variable, this should be used instead of the passed url 86 $this->oembed->fetch( 'https://example.com/provider/endpoint?url=https://example.com/foo', 'https://example.com/bar', array( 87 'discovered' => true 88 ) ); 89 90 remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) ); 91 92 $url_query = parse_url( $this->_provider_url, PHP_URL_QUERY ); 93 parse_str( $url_query, $query_variables ); 94 $this->assertEquals( 'https://example.com/foo', $query_variables['url'] ); 95 } 96 97 /** 98 * @ticket 34335 99 */ 100 public function test_fetch_of_provider_without_url() { 101 add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 ); 102 103 //Discovered endpoint does not contain an url query variable, we should insert the passed url 104 $this->oembed->fetch( 'https://example.com/provider/endpoint', 'https://example.com/bar', array( 105 'discovered' => true 106 ) ); 107 108 remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) ); 109 110 $url_query = parse_url( $this->_provider_url, PHP_URL_QUERY ); 111 parse_str( $url_query, $query_variables ); 112 $this->assertEquals( 'https://example.com/bar', $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 } 72 128 }