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

Update how Imgur IDs are parsed #5485

Merged
merged 2 commits into from
Oct 10, 2020
Merged

Update how Imgur IDs are parsed #5485

merged 2 commits into from
Oct 10, 2020

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Oct 9, 2020

Summary

Fixes #5482
Fixes #4697

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).

@google-cla google-cla bot added the cla: yes Signed the Google CLA label Oct 9, 2020
@pierlon pierlon added this to the v2.0.5 milestone Oct 9, 2020
@pierlon
Copy link
Contributor Author

pierlon commented Oct 9, 2020

This PR is in counterpart with ampproject/amphtml#30589 that fixes how singular Imgur IDs are sanitized. Currently embedding a Imgur gallery or album works fine, but if embedding a singular Imgur image, amp-imgur prepends the Imgur ID with a/, which results in a 404 when loading the embed.

@pierlon pierlon requested a review from westonruter October 9, 2020 05:06
@pierlon pierlon marked this pull request as ready for review October 9, 2020 05:06
@pierlon pierlon added the WS:Core Work stream for Plugin core label Oct 9, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2020

Plugin builds for 7a07dac are ready 🛎️!

@westonruter
Copy link
Member

So is #4697 valid? Instead of:

<amp-imgur
    data-imgur-id="2q6AS6i"
    layout="responsive"
    width="540"
    height="633"
  >
  </amp-imgur>

Should they have provided:

<amp-imgur
    data-imgur-id="a/2q6AS6i"
    layout="responsive"
    width="540"
    height="633"
  >
  </amp-imgur>

?

@pierlon
Copy link
Contributor Author

pierlon commented Oct 9, 2020

I would say it still is valid. Based on the reproduction steps provided the URL in question was https://imgur.com/gallery/2q6AS6i, which when previously parsed the ID would be 2q6AS6i. The iframe URL would then be https://imgur.com/2q6AS6i, instead of the expected https://imgur.com/a/2q6AS6i.

@westonruter
Copy link
Member

I'm seeing the amp-imgur getting a width of 580 and a height of 870:

Screen Shot 2020-10-09 at 13 12 47

This is coming from the $attr which is passed into AMP_Imgur_Embed_Handler::filter_embed_oembed_html(), which is coming from the initial oEmbed response data:

{
    "version": "1.0",
    "type": "rich",
    "provider_name": "Imgur",
    "provider_url": "https://imgur.com",
    "width": 580,
    "height": 870,
    "html": "<blockquote class=\"imgur-embed-pub\" lang=\"en\" data-id=\"a/rAG6Q2w\"><a href=\"https://imgur.com/a/rAG6Q2w\">View post on imgur.com</a></blockquote><script async src=\"//s.imgur.com/min/embed.js\" charset=\"utf-8\"></script>"
}

There is no width or height in the actual html, even though it's attempting to parse it out. Is this dead code?

if ( preg_match( '/width=["\']?(\d+)/', $return, $matches ) ) {
$attr['width'] = $matches[1];
}
if ( preg_match( '/height=["\']?(\d+)/', $return, $matches ) ) {
$attr['height'] = $matches[1];
}
if ( empty( $attr['height'] ) ) {
return $return;
}
$attributes = wp_array_slice_assoc( $attr, [ 'width', 'height' ] );
if ( empty( $attr['width'] ) ) {
$attributes['layout'] = 'fixed-height';
$attributes['width'] = 'auto';
}

@westonruter
Copy link
Member

The width and height issue appears to be specific to https://imgur.com/a/rAG6Q2w

@westonruter
Copy link
Member

The excessive height seems to be a bug with Imgur's data response.

Nevertheless, should we be parsing the width and height when there is nothing in the HTML?

@pierlon
Copy link
Contributor Author

pierlon commented Oct 9, 2020

Yea it does seem to be dead code. I'll remove it.

@westonruter
Copy link
Member

Rebasing onto develop to fix build failure.

@westonruter
Copy link
Member

I would say it still is valid. Based on the reproduction steps provided the URL in question was https://imgur.com/gallery/2q6AS6i, which when previously parsed the ID would be 2q6AS6i. The iframe URL would then be https://imgur.com/2q6AS6i, instead of the expected https://imgur.com/a/2q6AS6i.

But https://imgur.com/2q6AS6i/embed?pub=true is a failure whereas https://imgur.com/a/2q6AS6i/embed?pub=true succeeds.

So then with the reversion of ampproject/amphtml#30589 wouldn't this be required?

<amp-imgur
    data-imgur-id="a/2q6AS6i"
    layout="responsive"
    width="540"
    height="633"
  >
  </amp-imgur>

@westonruter
Copy link
Member

Wait, so this is the case actually. In #4697 the issue was for embedding https://imgur.com/gallery/2q6AS6i.

Before this PR it was generating (which currently works until ampproject/amphtml#30589 is merged):

<amp-imgur width="580" height="870" data-imgur-id="2q6AS6i" class="i-amphtml-layout-fixed i-amphtml-layout-size-defined" style="width:580px;height:870px;" i-amphtml-layout="fixed"></amp-imgur>

Whereas with this PR, the result is:

<amp-imgur width="580" height="870" data-imgur-id="a/2q6AS6i" class="i-amphtml-layout-fixed i-amphtml-layout-size-defined" style="width:580px;height:870px;" i-amphtml-layout="fixed"></amp-imgur>

The explicit a/ here will ensure that https://imgur.com/a/2q6AS6i/embed?pub=true is the result.

@westonruter westonruter merged commit 7e06ed2 into develop Oct 10, 2020
@westonruter westonruter deleted the fix/5482-imgur-embed branch October 10, 2020 21:37
westonruter pushed a commit that referenced this pull request Oct 10, 2020
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. cla: yes Signed the Google CLA WS:Core Work stream for Plugin core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[amp-imgur] Some Imgur urls are not supported by AMP-WP plugin Imgur post embed gives 404 error
2 participants