Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 5 additions & 1 deletion src/wp-includes/class-wp-oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ public function get_provider( $url, $args = '' ) {
}

foreach ( $this->providers as $matchmask => $data ) {
list( $providerurl, $regex ) = $data;
if ( ! is_array( $data ) || ! isset( $data[0] ) ) {
Comment thread
Sukhendu2002 marked this conversation as resolved.
Outdated
continue;
}
$providerurl = $data[0];
$regex = $data[1] ?? false;
Comment thread
Sukhendu2002 marked this conversation as resolved.
Outdated

// Turn the asterisk-type provider URLs into regex.
if ( ! $regex ) {
Expand Down
58 changes: 58 additions & 0 deletions tests/phpunit/tests/oembed/wpOembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,62 @@ 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 ) );
}

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

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

set_error_handler( $error_handler );

// Provider with only index 0 set (no regex flag) — should default $regex to false.
$this->oembed->providers['https://example.site/*'] = array( 'https://example.site/api/oembed' );

$result = $this->oembed->get_provider( 'https://example.site/video/123' );

restore_error_handler();

$this->assertSame( 'https://example.site/api/oembed', $result );
$this->assertSame( array(), $warnings, 'PHP warnings were raised: ' . implode( ', ', $warnings ) );
}
}
Loading