Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wp-includes/class-wp-oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ public function get_provider( $url, $args = '' ) {
}

foreach ( $this->providers as $matchmask => $data ) {
if (
! is_array( $data ) ||
count( $data ) < 2 ||
! array_key_exists( 0, $data ) ||
! array_key_exists( 1, $data )
) {
continue;
}
Comment thread
Sukhendu2002 marked this conversation as resolved.
Outdated
list( $providerurl, $regex ) = $data;

// Turn the asterisk-type provider URLs into regex.
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/tests/oembed/wpOembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,34 @@ public function test_wp_filter_pre_oembed_result_multisite_restores_state_if_no_
$this->assertFalse( $actual );
$this->assertSame( $current_blog_id, get_current_blog_id() );
}

/**
* @ticket 65068
*
* @covers ::get_provider
*/
public function test_get_provider_skips_malformed_provider_entries() {
$warnings = array();

$error_handler = function ( $errno, $errstr ) use ( &$warnings ) {
if ( E_WARNING === $errno ) {
$warnings[] = $errstr;
}
return false;
};

set_error_handler( $error_handler );

$this->oembed->providers['bad_provider'] = array(
'url' => '#https?://example\.site/.*#i',
'endpoint' => 'https://example.site/api/oembed',
);

$result = $this->oembed->get_provider( 'https://en.wikipedia.org/wiki/Rickrolling' );

restore_error_handler();

$this->assertFalse( $result );
$this->assertSame( array(), $warnings, 'PHP warnings were raised: ' . implode( ', ', $warnings ) );
}
}
Loading