diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 3bc5de556c49e..57c5a6b84beb3 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -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] ) ) { + continue; + } + $providerurl = $data[0]; + $regex = $data[1] ?? false; // Turn the asterisk-type provider URLs into regex. if ( ! $regex ) { diff --git a/tests/phpunit/tests/oembed/wpOembed.php b/tests/phpunit/tests/oembed/wpOembed.php index bc10c2a10a7eb..e5a3a7cbb409c 100644 --- a/tests/phpunit/tests/oembed/wpOembed.php +++ b/tests/phpunit/tests/oembed/wpOembed.php @@ -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 ) ); + } }