From afa07821f9a287af3db8d51df05f90ea491c0d99 Mon Sep 17 00:00:00 2001 From: Sidharth Kshatriya Date: Thu, 21 Jul 2016 09:24:54 +0530 Subject: [PATCH] tack on https protocol during iframe conversion if src is protocol relative --- src/Pass/IframeTagTransformPass.php | 5 +++- src/Utility/ActionTakenType.php | 2 +- .../iframe-http-to-https-conversion.html | 6 +++++ .../iframe-http-to-https-conversion.html.out | 23 ++++++++++++++----- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Pass/IframeTagTransformPass.php b/src/Pass/IframeTagTransformPass.php index 5f68c77c..deb2385f 100644 --- a/src/Pass/IframeTagTransformPass.php +++ b/src/Pass/IframeTagTransformPass.php @@ -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]; diff --git a/src/Utility/ActionTakenType.php b/src/Utility/ActionTakenType.php index 9562202b..37f437cb 100644 --- a/src/Utility/ActionTakenType.php +++ b/src/Utility/ActionTakenType.php @@ -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'; diff --git a/tests/test-data/fragment-html/iframe-http-to-https-conversion.html b/tests/test-data/fragment-html/iframe-http-to-https-conversion.html index 42c14349..c5ffa1be 100644 --- a/tests/test-data/fragment-html/iframe-http-to-https-conversion.html +++ b/tests/test-data/fragment-html/iframe-http-to-https-conversion.html @@ -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"> + + + \ No newline at end of file diff --git a/tests/test-data/fragment-html/iframe-http-to-https-conversion.html.out b/tests/test-data/fragment-html/iframe-http-to-https-conversion.html.out index 304e68d5..a7df3ee3 100644 --- a/tests/test-data/fragment-html/iframe-http-to-https-conversion.html.out +++ b/tests/test-data/fragment-html/iframe-http-to-https-conversion.html.out @@ -1,19 +1,30 @@ + + ORIGINAL HTML --------------- -Line 1: +Line 1: +Line 6: +Line 7: Transformations made from HTML tags to AMP custom tags -------------------------------------------------------