Skip to content

Commit

Permalink
Youtube Shortcode: Updates regex (#10224)
Browse files Browse the repository at this point in the history
Brings upstream changes from wp.com discussed in D17568-code and D17868-code.

#### Changes proposed in this Pull Request:

* Updates the regex used in the Youtube embed sniffing to allow for some cases previously missed.

#### Testing instructions:

* See D17568-code

#### Proposed changelog entry for your changes:

* Updates YouTube regex for converting `object` era-embeds to a shortcode.
  • Loading branch information
kraftbj authored and jeherve committed Dec 3, 2018
1 parent ebb2260 commit 89f6290
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/shortcodes/youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function youtube_embed_to_short_code( $content ) {
}

// older codes
$regexp = '!<object width="\d+" height="\d+"><param name="movie" value="https?://www\.youtube\.com/v/([^"]+)"></param>(?:<param name="\w+" value="[^"]*"></param>)*<embed src="https?://www\.youtube\.com/v/(.+)" type="application/x-shockwave-flash"(?: \w+="[^"]*")* width="\d+" height="\d+"></embed></object>!i';
$regexp = '!<object(.*?)>.*?<param\s+name=[\'"]movie[\'"]\s+value=[\'"](https?:)?//www\.youtube\.com/v/([^\'"]+)[\'"].*?>.*?</object>!i';
$regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES );
$old_regexp = '!<embed(?:\s+\w+="[^"]*")*\s+src="https?(?:\:|&#0*58;)//www\.youtube\.com/v/([^"]+)"(?:\s+\w+="[^"]*")*\s*(?:/>|>\s*</embed>)!';
$old_regexp_ent = str_replace( '&amp;#0*58;', '&amp;#0*58;|&#0*58;', htmlspecialchars( $old_regexp, ENT_NOQUOTES ) );
Expand All @@ -55,10 +55,10 @@ function youtube_embed_to_short_code( $content ) {
// <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
// 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 );
}

Expand Down

0 comments on commit 89f6290

Please sign in to comment.