Skip to content

Commit ca45c7a

Browse files
committed
Remove multiple instances of div#fb-root
1 parent c6869a9 commit ca45c7a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

includes/embeds/class-amp-facebook-embed.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ public function sanitize_raw_embeds( Document $dom ) {
9494
$parent_node->parentNode->removeChild( $parent_node );
9595
}
9696
}
97-
$fb_root->parentNode->removeChild( $fb_root );
97+
98+
// Remove other instances of <div id="fb-root">.
99+
$fb_root_query = $dom->xpath->query( '//div[ @id = "fb-root" ]' );
100+
foreach ( $fb_root_query as $fb_root ) {
101+
$fb_root->parentNode->removeChild( $fb_root );
102+
}
98103
}
99104
}
100105

tests/php/test-amp-facebook-embed.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public function get_raw_embed_dataset() {
219219
'',
220220
],
221221

222+
'remove_multiple_fb_root' => [
223+
str_repeat( '<div id="fb-root"></div>', 5 ) . str_repeat( '<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"></script>', 5 ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
224+
'',
225+
],
226+
222227
'remove_empty_p_tag' => [
223228
'<p><script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"></script></p><div id="fb-root"></div>', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
224229
'',

0 commit comments

Comments
 (0)