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

Prevent wpautop() from modifying Twitter embed #3874

Merged
merged 2 commits into from
Dec 4, 2019

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Dec 3, 2019

Summary

The cause of the duplication was due to wpautop() mucking with the content, wrapping tags it deems as "block-level" with a <p> which causes the blockquote tag to be placed outside the AMP component. Once outside, the blockquote is santitized as a raw embed and another Twitter AMP component would be rendered.

Removing the HTML oEmbed filter in AMP_Twitter_Embed_Handler will allow for wpautop to process the original HTML, and allows the raw embed sanitizer within the class to convert it into an AMP component, without any interference.

Fixes #3865.

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Dec 3, 2019
@pierlon pierlon requested a review from westonruter December 3, 2019 01:05
@westonruter
Copy link
Member

Oh, I see. This now brings to mind an issue we had with placeholder content in amp-iframe, namely that we had to use a span to prevent this from happening.

This being the case, I am wary of modifying the behavior of wpautop as this seems like it could cause headaches later. Instead, I suggest populating the Twitter placeholder content with a... placeholder. For example, the placeholder could be some unique string of characters which then get replaced with the actual blockquote after wpautop has run.

@pierlon
Copy link
Contributor Author

pierlon commented Dec 3, 2019

Just wanted to point out that dynamic blocks are rendered by preventing wpautop from being run on the block content. I agree with using a placeholder for the placeholder (:laughing:) though, it would seem to be more future-proof.

@pierlon pierlon changed the title Run wpautop() last on post content Prevent wpautop() from modifying Twitter embed Dec 3, 2019
@pierlon pierlon force-pushed the fix/3865-duplicate-twitter-embed branch from 0ef896f to 118facf Compare December 3, 2019 16:56
@pierlon
Copy link
Contributor Author

pierlon commented Dec 3, 2019

Rebased to remove the commit messing with wpautop.

@westonruter westonruter added this to the v1.4.2 milestone Dec 4, 2019
@westonruter westonruter merged commit 4b39169 into develop Dec 4, 2019
@westonruter westonruter deleted the fix/3865-duplicate-twitter-embed branch December 4, 2019 16:06
@westonruter westonruter modified the milestones: v1.4.2, v1.5 Dec 4, 2019
@westonruter
Copy link
Member

@pierlon I thought this PR was going to be needed for 1.4.2, hence the squash merge. But then I found it wouldn't cherry-pick cleanly onto the 1.4 branch. This is due to #1753, which is only in develop (which this PR reverts part of). So I believe this isn't needed in a patch release prior to 1.5.

@pierlon
Copy link
Contributor Author

pierlon commented Dec 4, 2019

Yes that makes sense.

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

$this->assertEquals( $content, $expected );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierlon For PHPUnit assertion, the expected value always comes first, followed by the actual value.

This is important because PHPUnit will tell you what it expected, and what it got instead. If you put the values in the wrong order (like here), this is misleading and causes you to look in the wrong places.

I'm rectifying this in #3758, as I'm touching those tests anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for pointing that out, noted 👍 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Twitter embed in Classic Block is duplicated
4 participants