From 2a7657335e228cde48e72e582f48e9fd7a6d3876 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Tue, 14 Apr 2026 12:46:35 +0530 Subject: [PATCH 1/2] Fix: Add validation for oEmbed provider data to prevent PHP warnings --- src/wp-includes/class-wp-oembed.php | 8 +++++++ tests/phpunit/tests/oembed/wpOembed.php | 30 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 3bc5de556c49e..6ba55bc451a0a 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -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; + } list( $providerurl, $regex ) = $data; // Turn the asterisk-type provider URLs into regex. diff --git a/tests/phpunit/tests/oembed/wpOembed.php b/tests/phpunit/tests/oembed/wpOembed.php index 288d1742d373e..96bbf9694f53a 100644 --- a/tests/phpunit/tests/oembed/wpOembed.php +++ b/tests/phpunit/tests/oembed/wpOembed.php @@ -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 ) ); + } } From 506e75282df9db26410fd42fdd53db592c6d052d Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 15 Apr 2026 14:37:24 +0530 Subject: [PATCH 2/2] fix: Default regex to false for oEmbed providers missing index 1 --- src/wp-includes/class-wp-oembed.php | 10 +++------ tests/phpunit/tests/oembed/wpOembed.php | 28 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 6ba55bc451a0a..57c5a6b84beb3 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -273,15 +273,11 @@ 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 ) - ) { + if ( ! is_array( $data ) || ! isset( $data[0] ) ) { continue; } - list( $providerurl, $regex ) = $data; + $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 96bbf9694f53a..8cf894c849dd6 100644 --- a/tests/phpunit/tests/oembed/wpOembed.php +++ b/tests/phpunit/tests/oembed/wpOembed.php @@ -306,4 +306,32 @@ public function test_get_provider_skips_malformed_provider_entries() { $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 ) ); + } }