From 7dd8a1364aa5dc1d9aba77e8f1f4cdb350f36d17 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 16 Jun 2015 00:34:06 +0000 Subject: [PATCH] In the `youtube_embed_url` embed handler, make `embed` a non-capturing group that alternately matches for `v` - YouTube supports both URL paths. Add unit test cases. Props dmchale for some patch work. Fixes #32161. git-svn-id: https://develop.svn.wordpress.org/trunk@32787 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 2 +- tests/phpunit/tests/media.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 4007fec7b9..57037710b0 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2312,7 +2312,7 @@ function wp_maybe_load_embeds() { return; } - wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/embed/([^/]+)#i', 'wp_embed_handler_youtube' ); + wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube' ); wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' ); diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 5a7278e8ce..bfd9e81b3c 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -120,8 +120,6 @@ CAP; * @ticket 23149 */ function test_youtube_com_secure_embed() { - global $wp_embed; - $out = wp_oembed_get( 'http://www.youtube.com/watch?v=oHg5SJYRHA0' ); $this->assertContains( 'https://www.youtube.com/embed/oHg5SJYRHA0?feature=oembed', $out ); @@ -132,6 +130,18 @@ CAP; $this->assertContains( 'https://www.youtube.com/embed/zHjMoNQN7s0?feature=oembed', $out ); } + function test_youtube_embed_url() { + global $wp_embed; + $out = $wp_embed->autoembed( 'https://www.youtube.com/embed/QcIy9NiNbmo' ); + $this->assertContains( 'https://youtube.com/watch?v=QcIy9NiNbmo', $out ); + } + + function test_youtube_v_url() { + global $wp_embed; + $out = $wp_embed->autoembed( 'https://www.youtube.com/v/QcIy9NiNbmo' ); + $this->assertContains( 'https://youtube.com/watch?v=QcIy9NiNbmo', $out ); + } + /** * @ticket 23776 */