Skip to content

Commit 506e752

Browse files
committed
fix: Default regex to false for oEmbed providers missing index 1
1 parent 2a76573 commit 506e752

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/wp-includes/class-wp-oembed.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,11 @@ public function get_provider( $url, $args = '' ) {
273273
}
274274

275275
foreach ( $this->providers as $matchmask => $data ) {
276-
if (
277-
! is_array( $data ) ||
278-
count( $data ) < 2 ||
279-
! array_key_exists( 0, $data ) ||
280-
! array_key_exists( 1, $data )
281-
) {
276+
if ( ! is_array( $data ) || ! isset( $data[0] ) ) {
282277
continue;
283278
}
284-
list( $providerurl, $regex ) = $data;
279+
$providerurl = $data[0];
280+
$regex = $data[1] ?? false;
285281

286282
// Turn the asterisk-type provider URLs into regex.
287283
if ( ! $regex ) {

tests/phpunit/tests/oembed/wpOembed.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,32 @@ public function test_get_provider_skips_malformed_provider_entries() {
306306
$this->assertFalse( $result );
307307
$this->assertSame( array(), $warnings, 'PHP warnings were raised: ' . implode( ', ', $warnings ) );
308308
}
309+
310+
/**
311+
* @ticket 65068
312+
*
313+
* @covers ::get_provider
314+
*/
315+
public function test_get_provider_handles_provider_without_regex_flag() {
316+
$warnings = array();
317+
318+
$error_handler = function ( $errno, $errstr ) use ( &$warnings ) {
319+
if ( E_WARNING === $errno ) {
320+
$warnings[] = $errstr;
321+
}
322+
return false;
323+
};
324+
325+
set_error_handler( $error_handler );
326+
327+
// Provider with only index 0 set (no regex flag) — should default $regex to false.
328+
$this->oembed->providers['https://example.site/*'] = array( 'https://example.site/api/oembed' );
329+
330+
$result = $this->oembed->get_provider( 'https://example.site/video/123' );
331+
332+
restore_error_handler();
333+
334+
$this->assertSame( 'https://example.site/api/oembed', $result );
335+
$this->assertSame( array(), $warnings, 'PHP warnings were raised: ' . implode( ', ', $warnings ) );
336+
}
309337
}

0 commit comments

Comments
 (0)