From eb9b2cb472227da16dc5923beccbc57c246ea650 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 26 Sep 2018 12:33:25 -0500 Subject: [PATCH 1/3] Youtube Shortcode: Updates regex Brings upstream changes from wp.com discussed in D17568-code and D17868-code. --- modules/shortcodes/youtube.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/shortcodes/youtube.php b/modules/shortcodes/youtube.php index 79af6f94b7e8f..f0aa1e1b35121 100644 --- a/modules/shortcodes/youtube.php +++ b/modules/shortcodes/youtube.php @@ -32,7 +32,7 @@ function youtube_embed_to_short_code( $content ) { } // older codes - $regexp = '!(?:)*!i'; + $regexp = '!]+?)>.*?]*?>.*?!is'; $regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES ); $old_regexp = '!|>\s*)!'; $old_regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) ); @@ -55,10 +55,10 @@ function youtube_embed_to_short_code( $content ) { // // As shown at the start of function, previous YouTube didn't '?' // the 1st field-value pair. - if ( in_array( $reg, array( 'ifr_regexp', 'ifr_regexp_ent' ) ) ) { + if ( in_array( $reg, array( 'ifr_regexp', 'ifr_regexp_ent', 'regexp', 'regexp_ent' ) ) ) { $params = $match[1]; - if ( 'ifr_regexp_ent' == $reg ) { + if ( in_array( $reg, array( 'ifr_regexp_ent', 'regexp_ent' ) ) ) { $params = html_entity_decode( $params ); } From e4c966d6ce59ef42260a4283d30af470229e2da5 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Mon, 3 Dec 2018 13:48:38 +0100 Subject: [PATCH 2/3] Improve the matching of the youtube shortcode reversal again. Merges r184358-wpcom In D17568-code and D17868-code we improved this code. Those changes accidentally got reversed in D18511-code I was reviewing #10224 which would merge the original changes into Jetpack and noted the 's' modifier. Unfortunately we can't include that here because it means on long but malformed post content we go into an infinite loop because of the .*? in the RegEx. This means we can't match objects/mangled objects which have a newline within them but we can match more that we were Diff: D21652-code --- modules/shortcodes/youtube.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/shortcodes/youtube.php b/modules/shortcodes/youtube.php index f0aa1e1b35121..a86c456b4ddf0 100644 --- a/modules/shortcodes/youtube.php +++ b/modules/shortcodes/youtube.php @@ -32,7 +32,7 @@ function youtube_embed_to_short_code( $content ) { } // older codes - $regexp = '!]+?)>.*?]*?>.*?!is'; + $regexp = '!.*?.*?!i'; $regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES ); $old_regexp = '!|>\s*)!'; $old_regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) ); From d3bd4ef82f5b9e2881f962082efe6c225c86e297 Mon Sep 17 00:00:00 2001 From: And Finally Date: Mon, 3 Dec 2018 16:44:59 +0100 Subject: [PATCH 3/3] YouTube: escape . characters when matching Youtube.com @see https://github.com/Automattic/jetpack/pull/10224#commitcomment-31535800 --- modules/shortcodes/youtube.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/shortcodes/youtube.php b/modules/shortcodes/youtube.php index a86c456b4ddf0..048eb09b45867 100644 --- a/modules/shortcodes/youtube.php +++ b/modules/shortcodes/youtube.php @@ -32,7 +32,7 @@ function youtube_embed_to_short_code( $content ) { } // older codes - $regexp = '!.*?.*?!i'; + $regexp = '!.*?.*?!i'; $regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES ); $old_regexp = '!|>\s*)!'; $old_regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) );