From 289965b097b0f3585bbd1f7ad610ada2655b7768 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 26 May 2017 23:09:42 +0000 Subject: [PATCH] Widgets: Normalize YouTube and Vimeo URLs in `video` shortcode (primarily for Video widget) to work around ME.js 2.22 bug. Props timmydcrawford, jnylen0, westonruter. See #32417, #39994. Fixes #40866. git-svn-id: https://develop.svn.wordpress.org/trunk@40847 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 14 +++++++++++++ tests/phpunit/tests/media.php | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 81d83d8cc0..a7239297ab 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2546,6 +2546,20 @@ function wp_video_shortcode( $attr, $content = '' ) { wp_enqueue_script( 'wp-mediaelement' ); } + // Mediaelement has issues with some URL formats for Vimeo and YouTube, so + // update the URL to prevent the ME.js player from breaking. + if ( 'mediaelement' === $library ) { + if ( $is_youtube ) { + // Remove `feature` query arg and force SSL - see #40866. + $atts['src'] = remove_query_arg( 'feature', $atts['src'] ); + $atts['src'] = set_url_scheme( $atts['src'], 'https' ); + } elseif ( $is_vimeo ) { + // Remove all query arguments and force SSL - see #40866. + $parsed_vimeo_url = wp_parse_url( $atts['src'] ); + $atts['src'] = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path']; + } + } + /** * Filters the class attribute for the video shortcode output container. * diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index bccab12d3e..4eccd25fb5 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -723,6 +723,43 @@ VIDEO; $this->assertContains( 'class="foobar"', $actual ); } + /** + * @ticket 40866 + * @depends test_video_shortcode_body + */ + function test_wp_video_shortcode_youtube_remove_feature() { + $actual = wp_video_shortcode( array( + 'src' => 'https://www.youtube.com/watch?v=i_cVJgIz_Cs&feature=youtu.be', + ) ); + + $this->assertNotContains( 'feature=youtu.be', $actual ); + } + + /** + * @ticket 40866 + * @depends test_video_shortcode_body + */ + function test_wp_video_shortcode_youtube_force_ssl() { + $actual = wp_video_shortcode( array( + 'src' => 'http://www.youtube.com/watch?v=i_cVJgIz_Cs', + ) ); + + $this->assertContains( 'src="https://www.youtube.com/watch?v=i_cVJgIz_Cs', $actual ); + } + + /** + * @ticket 40866 + * @depends test_video_shortcode_body + */ + function test_wp_video_shortcode_vimeo_force_ssl_remove_query_args() { + $actual = wp_video_shortcode( array( + 'src' => 'http://vimeo.com/190372437?blah=meh', + ) ); + + $this->assertContains( 'src="https://vimeo.com/190372437', $actual ); + $this->assertNotContains( 'blah=meh', $actual ); + } + /** * Test [video] shortcode processing *