Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap all embeds with paragraph tags #4650

Closed
wants to merge 51 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7401840
Sanitize DailyMotion embeds
pierlon Apr 1, 2020
3c57f35
Sanitize gfycat embeds
pierlon Apr 27, 2020
7e1ccf0
Unwrap Instagram embeds
pierlon Apr 27, 2020
3bb9d3e
Unwrap Scribd embeds
pierlon May 4, 2020
be260f8
Unwrap SoundCloud embeds
pierlon May 5, 2020
d7f3421
Sanitize Twitter timelines and moments
pierlon May 8, 2020
9c17878
Unwrap Vimeo embeds
pierlon May 8, 2020
91cdd3d
Sanitize YouTube embeds
pierlon May 8, 2020
ce5ef79
Sanitize WordPress TV embeds
pierlon May 8, 2020
575f173
Sanitize Hulu embeds
pierlon May 8, 2020
d789507
Fix lint errors
pierlon May 8, 2020
2ee90b4
Merge branch 'develop' into fix/4450-wrapped-embeds
pierlon May 16, 2020
bd606bf
Make child element count more robust
pierlon May 18, 2020
8e492b2
Extract base embed URLs as class constants
pierlon May 18, 2020
3f4f9ae
Get dimensions from iframe if available
pierlon May 18, 2020
085d1cc
Refactor logic for removing script sibling
pierlon May 18, 2020
050b9e7
Simplify logic for retrieving embed IDs
pierlon May 18, 2020
6893a47
Fix tests
pierlon May 19, 2020
34ca29c
Implement the Template Method design pattern
pierlon May 21, 2020
c955f45
Sanitize Imgur embeds
pierlon May 21, 2020
21ae657
Sanitize Tumblr embeds
pierlon May 21, 2020
8850a0f
Mock tests for DailyMotion
pierlon May 21, 2020
decbb49
Sanitize Reddit embeds
pierlon May 22, 2020
361b712
Implement `get_raw_embed_nodes` in `AMP_Base_Embed_Handler`
pierlon May 22, 2020
28b4394
Remove `get_parent_element` method
pierlon May 22, 2020
c663535
Make YouTube xpath query more specific
pierlon Jun 5, 2020
1f4df49
Merge branch 'develop' into fix/4450-wrapped-embeds
pierlon Jun 17, 2020
573334a
Fix lint issues
pierlon Jun 18, 2020
c695846
Mock Instagram embed test
pierlon Jun 18, 2020
67bf708
Update docblocks specifying alternative return values
pierlon Jun 18, 2020
e1c768d
Fix test cases for Dailymotion, Twitter, Gfycat and WordPress TV embeds
pierlon Jun 19, 2020
5b2ece9
Update mocked responses
pierlon Jun 19, 2020
5fa1cdb
Sanitize Meetup embeds
pierlon Jun 19, 2020
85b55cb
Sanitize Issuu embeds
pierlon Jun 19, 2020
996862a
Sanitize CrowdSignal embeds
pierlon Jun 19, 2020
1cd716f
Merge branch 'develop' into fix/4450-wrapped-embeds
pierlon Jun 19, 2020
4885788
Sanitize Pinterest embeds
pierlon Jun 19, 2020
59066e8
Sanitize Vine embeds
pierlon Jun 21, 2020
7c03ced
Add `Registerable` interface to indicate embed handlers that hook int…
pierlon Jun 21, 2020
1d91d0b
Fix lint and static analysis errors
pierlon Jun 21, 2020
cb3ef8b
Merge branch 'develop' into fix/4450-wrapped-embeds
pierlon Jun 21, 2020
beadf51
Rename `whitelist_sanitizer` to `validating_sanitizer`
pierlon Jun 21, 2020
b0157a1
Mark Pinterest and Vine embed handlers as registerable
pierlon Jun 25, 2020
b3a2c1c
Add oEmbed provider URLs for embeds not supported in WP 5.1
pierlon Jun 25, 2020
dfaf3e5
Fix YouTube embed test
pierlon Jun 25, 2020
244b53d
Merge branch 'develop' into fix/4450-wrapped-embeds
pierlon Jun 25, 2020
a857f25
Remove unused vars
pierlon Jun 25, 2020
434660a
Fix tests failures related to Gutenberg
pierlon Jun 25, 2020
986c036
Add oEmbed provider URL for Crowdsignal surveys on WP 5.2.
pierlon Jun 25, 2020
62fa5ae
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/4450-…
westonruter Jun 25, 2020
0860f48
Update phpdoc to reflect where methods do not return null
westonruter Jun 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update mocked responses
  • Loading branch information
pierlon committed Jun 19, 2020
commit 5b2ece9842d7dcc392046a2e8d1550c67af9bfb1
2 changes: 1 addition & 1 deletion tests/php/test-amp-dailymotion-embed-handler.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public function mock_http_request( $pre, $r, $url ) {
return $pre;
}

$body = '{"type":"video","version":"1.0","provider_name":"Dailymotion","provider_url":"https:\/\/www.dailymotion.com","title":"Snatched - Official Trailer 2 (HD)","description":"M\u00e1s info http:\/\/trailersyestrenos.es\/snatched-jonathan-levine\/ - TWITTER: https:\/\/twitter.com\/TrailersyEstren - FACEBOOK: https:\/\/www.facebook.com\/trailersyestrenos - GOOGLE+: https:\/\/www.google.com\/+TrailersyEstrenos Sinopsis: Una madre y una hija se enfrentar\u00e1n a distintos problemas que surgen mientras est\u00e1n de vacaciones Director: Jonathan Levine Reparto: Amy Schumer, Ike Barinholtz, Goldie Hawn, Christopher Meloni, Randall Park, Wanda Sykes, \u00d3scar Jaenada, Colin Quinn, Tom Bateman, Kevin Kane, Sharon M. Bell (El trailer pertenece a la productora y distribuidora de la pel\u00edcula y ha sido subido sin \u00e1nimo de lucro)","author_name":"Trailers y Estrenos","author_url":"https:\/\/www.dailymotion.com\/TrailersyEstrenos","width":480,"height":204,"html":"<iframe frameborder=\"0\" width=\"480\" height=\"204\" src=\"https:\/\/www.dailymotion.com\/embed\/video\/x5awwth\" allowfullscreen allow=\"autoplay\"><\/iframe>","thumbnail_url":"https:\/\/s1.dmcdn.net\/v\/J7Emb1UwvEwLi4MKo\/x120","thumbnail_width":214,"thumbnail_height":120}';
$body = '{"type":"video","version":"1.0","provider_name":"Dailymotion","provider_url":"https:\/\/www.dailymotion.com","title":"Snatched - Official Trailer 2 (HD)","description":"M\u00e1s info http:\/\/trailersyestrenos.es\/snatched-jonathan-levine\/ - TWITTER: https:\/\/twitter.com\/TrailersyEstren - FACEBOOK: https:\/\/www.facebook.com\/trailersyestrenos - GOOGLE+: https:\/\/www.google.com\/+TrailersyEstrenos Sinopsis: Una madre y una hija se enfrentar\u00e1n a distintos problemas que surgen mientras est\u00e1n de vacaciones Director: Jonathan Levine Reparto: Amy Schumer, Ike Barinholtz, Goldie Hawn, Christopher Meloni, Randall Park, Wanda Sykes, \u00d3scar Jaenada, Colin Quinn, Tom Bateman, Kevin Kane, Sharon M. Bell (El trailer pertenece a la productora y distribuidora de la pel\u00edcula y ha sido subido sin \u00e1nimo de lucro)","author_name":"Trailers y Estrenos","author_url":"https:\/\/www.dailymotion.com\/TrailersyEstrenos","width":500,"height":212,"html":"<iframe frameborder=\"0\" width=\"500\" height=\"212\" src=\"https:\/\/www.dailymotion.com\/embed\/video\/x5awwth\" allowfullscreen allow=\"autoplay\"><\/iframe>","thumbnail_url":"https:\/\/s2.dmcdn.net\/v\/J7Emb1UwvEwLi4MKo\/x120","thumbnail_width":214,"thumbnail_height":120}';

return [
'body' => $body,
8 changes: 4 additions & 4 deletions tests/php/test-amp-twitter-embed-handler.php
Original file line number Diff line number Diff line change
@@ -52,13 +52,13 @@ public function mock_http_request( $preempt, $r, $url ) {
} elseif ( false !== strpos( $url, '705219971425574912' ) ) {
$body = '{"url":"https:\/\/twitter.com\/sengineland\/status\/705219971425574912","author_name":"Search Engine Land","author_url":"https:\/\/twitter.com\/sengineland","html":"\u003Cblockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\"\u003E\u003Cp lang=\"en\" dir=\"ltr\"\u003EOn our way to the \u003Ca href=\"https:\/\/twitter.com\/hashtag\/GoogleDance?src=hash&amp;ref_src=twsrc%5Etfw\"\u003E#GoogleDance\u003C\/a\u003E! \u003Ca href=\"https:\/\/twitter.com\/hashtag\/SMX?src=hash&amp;ref_src=twsrc%5Etfw\"\u003E#SMX\u003C\/a\u003E \uD83D\uDC83\uD83C\uDFFB \u003Ca href=\"https:\/\/t.co\/N8kZ9M3eN4\"\u003Epic.twitter.com\/N8kZ9M3eN4\u003C\/a\u003E\u003C\/p\u003E&mdash; Search Engine Land (@sengineland) \u003Ca href=\"https:\/\/twitter.com\/sengineland\/status\/705219971425574912?ref_src=twsrc%5Etfw\"\u003EMarch 3, 2016\u003C\/a\u003E\u003C\/blockquote\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":500,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
} elseif ( false !== strpos( $url, 'moments%2F625792726546558977' ) ) {
$body = '{"url":"https:\/\/twitter.com\/i\/moments\/625792726546558977","title":"Michelle Obama Opens Special Olympics","html":"\u003Ca class=\"twitter-moment\" href=\"https:\/\/twitter.com\/i\/moments\/625792726546558977?ref_src=twsrc%5Etfw\"\u003EMichelle Obama Opens Special Olympics\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":550,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
$body = '{"url":"https:\/\/twitter.com\/i\/moments\/625792726546558977","title":"Michelle Obama Opens Special Olympics","html":"\u003Ca class=\"twitter-moment\" data-width=\"500\" data-dnt=\"true\" href=\"https:\/\/twitter.com\/i\/moments\/625792726546558977?ref_src=twsrc%5Etfw\"\u003EMichelle Obama Opens Special Olympics\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":500,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
} elseif ( false !== strpos( $url, 'lists%2Fweb-gdes' ) ) {
$body = '{"url":"https:\/\/twitter.com\/robertnyman\/lists\/web-gdes","title":"Web GDEs","html":"\u003Ca class=\"twitter-timeline\" href=\"https:\/\/twitter.com\/robertnyman\/lists\/web-gdes?ref_src=twsrc%5Etfw\"\u003EA Twitter List by robertnyman\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":null,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
$body = '{"url":"https:\/\/twitter.com\/robertnyman\/lists\/web-gdes","title":"Web GDEs","html":"\u003Ca class=\"twitter-timeline\" data-width=\"500\" data-height=\"750\" data-dnt=\"true\" href=\"https:\/\/twitter.com\/robertnyman\/lists\/web-gdes?ref_src=twsrc%5Etfw\"\u003EA Twitter List by robertnyman\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":500,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
} elseif ( false !== strpos( $url, 'wordpress%2Flikes' ) ) { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
$body = '{"url":"https:\/\/twitter.com\/WordPress\/likes","title":"","html":"\u003Ca class=\"twitter-timeline\" href=\"https:\/\/twitter.com\/WordPress\/likes?ref_src=twsrc%5Etfw\"\u003ETweets Liked by @WordPress\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":null,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
$body = '{"url":"https:\/\/twitter.com\/WordPress\/likes","title":"","html":"\u003Ca class=\"twitter-timeline\" data-width=\"500\" data-height=\"750\" data-dnt=\"true\" href=\"https:\/\/twitter.com\/WordPress\/likes?ref_src=twsrc%5Etfw\"\u003ETweets Liked by @WordPress\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":500,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
} elseif ( false !== strpos( $url, 'twitter.com%2Fwordpress' ) ) {
$body = '{"url":"https:\/\/twitter.com\/WordPress","title":"","html":"\u003Ca class=\"twitter-timeline\" href=\"https:\/\/twitter.com\/WordPress?ref_src=twsrc%5Etfw\"\u003ETweets by WordPress\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":null,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
$body = '{"url":"https:\/\/twitter.com\/WordPress","title":"","html":"\u003Ca class=\"twitter-timeline\" data-width=\"500\" data-height=\"750\" data-dnt=\"true\" href=\"https:\/\/twitter.com\/WordPress?ref_src=twsrc%5Etfw\"\u003ETweets by WordPress\u003C\/a\u003E\n\u003Cscript async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E\n","width":500,"height":null,"type":"rich","cache_age":"3153600000","provider_name":"Twitter","provider_url":"https:\/\/twitter.com","version":"1.0"}';
} else {
$body = '';
}
2 changes: 1 addition & 1 deletion tests/php/test-class-amp-gfycat-embed-handler.php
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ static function( $pre, $url ) {
if ( false === strpos( $url, 'tautwhoppingcougar' ) ) {
return $pre;
}
return '<iframe src=\'https://gfycat.com/ifr/tautwhoppingcougar#?secret=aBCUbiiIh5\' frameborder=\'0\' scrolling=\'no\' width=\'100\' height=\'100\' allowfullscreen></iframe>';
return '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="Melanie Raccoon riding bike-side angle (reddit)" src=\'https://gfycat.com/ifr/tautwhoppingcougar#?secret=Brq0P9wYCr\' data-secret=\'Brq0P9wYCr\' frameborder=\'0\' scrolling=\'no\' width=\'100%\' height=\'100%\'></iframe>';
},
10,
2
4 changes: 4 additions & 0 deletions tests/php/test-class-amp-hulu-embed-handler.php
Original file line number Diff line number Diff line change
@@ -98,6 +98,10 @@ public function test__conversion( $url, $expected ) {
$dom = AMP_DOM_Utils::get_dom_from_content( $filtered_content );
$embed->sanitize_raw_embeds( $dom );

if ( self::is_external_http_test_suite() && "<p>$url</p>" === trim( $filtered_content ) ) {
$this->markTestSkipped( 'Endpoint is down.' );
}

$content = AMP_DOM_Utils::get_content_from_dom( $dom );

$this->assertEquals( $expected, $content );
2 changes: 1 addition & 1 deletion tests/php/test-class-amp-wordpress-tv-embed-handler.php
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public function mock_http_request( $preempt, $r, $url ) {
}

return [
'body' => '{"type":"video","version":"1.0","title":null,"width":500,"height":281,"html":"<iframe width=\'500\' height=\'281\' src=\'https:\\/\\/video.wordpress.com\\/embed\\/yFCmLMGL?hd=0\' frameborder=\'0\' allowfullscreen><\\/iframe><script src=\'https:\\/\\/v0.wordpress.com\\/js\\/next\\/videopress-iframe.js?m=1435166243\'></script>"}', // phpcs:ignore
'body' => '{"type":"video","version":"1.0","title":null,"width":400,"height":225,"html":"<iframe width=\'400\' height=\'225\' src=\'https:\/\/video.wordpress.com\/embed\/yFCmLMGL?hd=1\' frameborder=\'0\' allowfullscreen><\/iframe><script src=\'https:\/\/v0.wordpress.com\/js\/next\/videopress-iframe.js?m=1435166243\'><\/script>"}', // phpcs:ignore
'headers' => [],
'response' => [
'code' => 200,