Skip to content

Commit

Permalink
Update amp-instagram embed regex (#4053)
Browse files Browse the repository at this point in the history
* Update amp-instagram embed regex

* Add test for raw embed
  • Loading branch information
pierlon authored and westonruter committed Jan 10, 2020
1 parent 6e6c34f commit 9c3a6c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-instagram-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class AMP_Instagram_Embed_Handler extends AMP_Base_Embed_Handler {
const SHORT_URL_HOST = 'instagr.am';
const URL_PATTERN = '#http(s?)://(www\.)?instagr(\.am|am\.com)/p/([^/?]+)#i';
const URL_PATTERN = '#https?:\/\/(www\.)?instagr(\.am|am\.com)\/(p|tv)\/([A-Za-z0-9-_]+)#i';

/**
* Default width.
Expand Down
19 changes: 16 additions & 3 deletions tests/php/test-amp-instagram-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
class AMP_Instagram_Embed_Test extends WP_UnitTestCase {
public function get_conversion_data() {
return [
'no_embed' => [
'no_embed' => [
'<p>Hello world.</p>',
'<p>Hello world.</p>' . PHP_EOL,
],
'simple_url' => [
'simple_url' => [
'https://instagram.com/p/7-l0z_p4A4/' . PHP_EOL,
'<p><amp-instagram data-shortcode="7-l0z_p4A4" data-captioned layout="responsive" width="600" height="600"></amp-instagram></p>' . PHP_EOL,
],
'short_url' => [
'simple_tv_url' => [
'https://instagram.com/tv/7-l0z_p4A4/' . PHP_EOL,
'<p><amp-instagram data-shortcode="7-l0z_p4A4" data-captioned layout="responsive" width="600" height="600"></amp-instagram></p>' . PHP_EOL,
],
'short_url' => [
'https://instagr.am/p/7-l0z_p4A4' . PHP_EOL,
'<p><amp-instagram data-shortcode="7-l0z_p4A4" data-captioned layout="responsive" width="600" height="600"></amp-instagram></p>' . PHP_EOL,
],
'short_tv_url' => [
'https://instagr.am/tv/7-l0z_p4A4' . PHP_EOL,
'<p><amp-instagram data-shortcode="7-l0z_p4A4" data-captioned layout="responsive" width="600" height="600"></amp-instagram></p>' . PHP_EOL,
],
];
}

Expand Down Expand Up @@ -95,6 +103,11 @@ public function get_raw_embed_dataset() {
'<amp-instagram data-shortcode="BhsgU3jh6xE" layout="responsive" width="600" height="600"></amp-instagram>' . "\n\n",
],

'blockquote_tv_embed' => [
wpautop( '<blockquote class="instagram-media" data-instgrm-permalink="https://www.instagram.com/tv/BhsgU3jh6xE/"><div style="padding: 8px;">Lorem ipsum</div></blockquote> <script async defer src="//www.instagram.com/embed.js"></script>' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine
'<amp-instagram data-shortcode="BhsgU3jh6xE" layout="responsive" width="600" height="600"></amp-instagram>' . "\n\n",
],

'blockquote_embed_notautop' => [
'<blockquote class="instagram-media" data-instgrm-permalink="https://www.instagram.com/p/BhsgU3jh6xE/"><div style="padding: 8px;">Lorem ipsum</div></blockquote> <script async defer src="//www.instagram.com/embed.js"></script>', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine
'<amp-instagram data-shortcode="BhsgU3jh6xE" layout="responsive" width="600" height="600"></amp-instagram> ',
Expand Down

0 comments on commit 9c3a6c7

Please sign in to comment.