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

Improve handling of WordPress post embeds #6665

Merged
merged 41 commits into from
Mar 3, 2022
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d4a6fd2
Excluded WP Embeds from being handled by iframe sanitizer
bartoszgadomski Oct 27, 2021
5b434eb
Changes in iframe-sanitizer removed; WordPress embed handler added fo…
bartoszgadomski Oct 29, 2021
c860f51
Tests created for AMP_WordPress_Embed_Handler class
bartoszgadomski Nov 9, 2021
42dda75
AMP_WordPress_Embed_Handler improved
bartoszgadomski Nov 10, 2021
d6efba4
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/809-h…
westonruter Nov 13, 2021
fdb57df
Improve tests and implement HTTP mocking
westonruter Nov 13, 2021
8ea5b97
AMP_WordPress_Embed_Handler changed to use sanitize_raw_embeds method…
bartoszgadomski Nov 15, 2021
00f0dfb
Paragraph unwrap moved to happen one step earlier
bartoszgadomski Nov 16, 2021
5de53b7
Removal of wp_oembed_add_host_js action moved from AMP_Theme_Support …
bartoszgadomski Nov 16, 2021
caad135
Code cleanup and improvements
bartoszgadomski Nov 16, 2021
23ebbec
AMP_WordPress_Embed_Handler tests updated
bartoszgadomski Nov 16, 2021
1411c6e
Merge branch 'develop' of https://github.com/ampproject/amp-wp into f…
bartoszgadomski Nov 16, 2021
5074b87
The 'test_get_scripts' updated to work with sanitize_raw_embeds
bartoszgadomski Nov 16, 2021
6338bd4
Test case for Test_AMP_Theme_Support updated
bartoszgadomski Nov 16, 2021
46805a4
AMP_WordPress_Embed_Handler test cases extended with two WP Embed blo…
bartoszgadomski Nov 16, 2021
6650a84
Blockquote and iframe pairs selection improved; tests cases extended …
bartoszgadomski Nov 16, 2021
d613f71
Utilize preceding-sibling XPath axis to simplify querying for iframe …
westonruter Nov 18, 2021
fb1eb6f
Unwrap iframes if preceding blockquote found and even when paragrpah …
westonruter Nov 18, 2021
b072215
Obtain attributes from iframe node rather than serializing and using …
westonruter Nov 18, 2021
d563a24
Remove data-secret from blockquote and reuse default overflow text
westonruter Nov 18, 2021
f1fb431
Update covers tags and combine register/unregister testing
westonruter Nov 18, 2021
976b832
De-duplicate test data with sprintf()
westonruter Nov 18, 2021
42b1461
Add test for HTML Embed code that users can use in non-WP context
westonruter Nov 18, 2021
76a3684
Add tests for output of get_post_embed_html() and ensure embed script…
westonruter Nov 18, 2021
d32ea7f
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/809-h…
westonruter Mar 1, 2022
eed4a04
Update since tag to 2.2.2
westonruter Mar 1, 2022
b1f44b6
Add tests for internal post embeds
westonruter Mar 2, 2022
c0184cc
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/809-h…
westonruter Mar 2, 2022
fa016ee
Add missing HTTP response mock
westonruter Mar 2, 2022
02ea5e2
Fix test_add_block_source_comments for Gutenberg 12.7
westonruter Mar 2, 2022
bc48ac2
Add debugging code
westonruter Mar 2, 2022
11cd07f
Use oembed_request_post_id for test
westonruter Mar 2, 2022
49fc7bf
Ensure video shortcode is registered to test_process_text_widgets
westonruter Mar 2, 2022
27de98b
Add assertions
westonruter Mar 2, 2022
0b311fc
Add more assertions
westonruter Mar 3, 2022
04c91f8
Add oembed_request_post_id filter sooner
westonruter Mar 3, 2022
505dbcc
Add yet more assertions to debug oEmbed problem on GHA
westonruter Mar 3, 2022
c72a71b
Add assertion for post data being created before test
westonruter Mar 3, 2022
f21d14f
Defer creation of post fixture until test
westonruter Mar 3, 2022
e884dbc
Remove obsolete debug code
westonruter Mar 3, 2022
73b4305
Update namespace for Attribute and Tag interfaces
westonruter Mar 3, 2022
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
30 changes: 22 additions & 8 deletions includes/sanitizers/class-amp-iframe-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,32 @@ public function sanitize() {
continue;
}

// Find the "figure" parent node, if exists.
$figure_node = null;
if ( $node->parentNode instanceof DOMElement && 'figure' === $node->parentNode->tagName ) {
$figure_node = $node->parentNode;
}
if ( $node->parentNode->parentNode instanceof DOMElement && 'figure' === $node->parentNode->parentNode->tagName ) {
$figure_node = $node->parentNode->parentNode;
}

/**
* Skip element if it's a "WP Embed", dedicated sanitizer will convert it to <amp-wordpress-embed>.
*
* @see: https://github.com/ampproject/amp-wp/issues/809
*/
if (
null !== $figure_node
&&
in_array( 'is-type-wp-embed', explode( ' ', $figure_node->getAttribute( Attribute::CLASS_ ) ), true )
) {
continue;
}

$this->did_convert_elements = true;
if ( empty( $normalized_attributes[ Attribute::LAYOUT ] ) && ! empty( $normalized_attributes[ Attribute::HEIGHT ] ) && ! empty( $normalized_attributes[ Attribute::WIDTH ] ) ) {

// Set layout to responsive if the iframe is aligned to full width.
$figure_node = null;
if ( $node->parentNode instanceof DOMElement && 'figure' === $node->parentNode->tagName ) {
$figure_node = $node->parentNode;
}
if ( $node->parentNode->parentNode instanceof DOMElement && 'figure' === $node->parentNode->parentNode->tagName ) {
$figure_node = $node->parentNode->parentNode;
}

if (
! empty( $this->args['align_wide_support'] )
&& $figure_node
Expand Down