Skip to content

Commit

Permalink
Merge pull request #126 from Lullabot/relative-url-iframe-conversion
Browse files Browse the repository at this point in the history
Tack on https protocol during iframe conversion if src is protocol relative
  • Loading branch information
sidkshatriya authored Jul 21, 2016
2 parents 8fbea5d + afa0782 commit 6aa510c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Pass/IframeTagTransformPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ protected function getIframeSrc(DOMQuery $el)
return [false, false];
}

if ($parsed_url['scheme'] == 'http') {
// Deal with relative URLs e.g "//example.com/iframe.html"
if (empty($parsed_url['scheme']) && strpos($src, '//') === 0) {
return ['https:' . $src, true];
} else if (!empty($parsed_url['scheme']) && $parsed_url['scheme'] == 'http') {
return [preg_replace('/(*UTF8)^http:/i', 'https:', $src), true];
} else {
return [$src, false];
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/ActionTakenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ActionTakenType
const DAILYMOTION_CONVERTED = 'dailymotion embed code was converted to the amp-dailymotion tag.';
const TWITTER_CONVERTED = 'twitter embed code was converted to the amp-twitter tag.';
const IFRAME_CONVERTED = 'tag was converted to the amp-iframe tag.';
const IFRAME_CONVERTED_AND_HTTPS = 'tag was converted to the amp-iframe tag. The url protocol was changed from http to https. amp-iframe does not support http';
const IFRAME_CONVERTED_AND_HTTPS = 'tag was converted to the amp-iframe tag. The url protocol was changed to explicitly use https. amp-iframe does not support http';
const YOUTUBE_IFRAME_CONVERTED = 'tag was converted to the amp-youtube tag.';
const SOUNDCLOUD_IFRAME_CONVERTED = 'tag was converted to the amp-soundcloud tag.';
const COMPONENT_SCRIPT_TAG_ADDED = 'custom component script tag added to head';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
height="450"
src="http://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"
width="600">
</iframe>

<iframe frameborder="0"
height="450"
src="//www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"
width="600">
</iframe>
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
<amp-iframe sandbox="allow-scripts allow-same-origin" layout="responsive" height="450" width="600" src="https://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"></amp-iframe>

<amp-iframe sandbox="allow-scripts allow-same-origin" layout="responsive" height="450" width="600" src="https://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"></amp-iframe>

ORIGINAL HTML
---------------
Line 1: <iframe frameborder="0"
Line 2: height="450"
Line 3: src="http://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"
Line 4: width="600">
Line 5: </iframe>
Line 1: <iframe frameborder="0"
Line 2: height="450"
Line 3: src="http://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"
Line 4: width="600">
Line 5: </iframe>
Line 6:
Line 7: <iframe frameborder="0"
Line 8: height="450"
Line 9: src="//www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html"
Line 10: width="600">
Line 11: </iframe>


Transformations made from HTML tags to AMP custom tags
-------------------------------------------------------

<iframe frameborder height="450" src="http://www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html" width="600"> at line 4
ACTION TAKEN: iframe tag was converted to the amp-iframe tag. The url protocol was changed from http to https. amp-iframe does not support http
ACTION TAKEN: iframe tag was converted to the amp-iframe tag. The url protocol was changed to explicitly use https. amp-iframe does not support http

<iframe frameborder height="450" src="//www.kickstarter.com/projects/1081571316/rhino-shield-the-impact-resistant-screen-protector/widget/video.html" width="600"> at line 10
ACTION TAKEN: iframe tag was converted to the amp-iframe tag. The url protocol was changed to explicitly use https. amp-iframe does not support http


AMP-HTML Validation Issues and Fixes
Expand Down

0 comments on commit 6aa510c

Please sign in to comment.