From ecd051905f0c8aa97590eb453d553dc678125a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Can=C3=A9vet?= Date: Sun, 8 Nov 2015 23:06:21 +0100 Subject: Fix issue 366, Problem when shaaring a link in Reader View of Firefox. --- application/Url.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/application/Url.php b/application/Url.php index a4ac2e73..e7c3a4cc 100644 --- a/application/Url.php +++ b/application/Url.php @@ -125,6 +125,19 @@ class Url } } + + private function removeFirefoxAboutReader($input){ + $output_array = []; + preg_match("%^about://reader\?url=(.*)%", $input, $output_array); + if(!empty($output_array)){ + $extractedUrl = preg_replace("%^about://reader\?url=(.*)%", "$1", $input); + $url = urldecode($extractedUrl); + }else{ + $url = $input; + } + return $url; + } + /** * Returns a string representation of this URL */ @@ -187,7 +200,8 @@ class Url { $this->cleanupQuery(); $this->cleanupFragment(); - return $this->toString(); + $url = $this->toString(); + return $this->removeFirefoxAboutReader($url); } /** -- cgit v1.2.3 From c9da01e749e5319d0c0f400cde06e71c0e7312d5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 24 Mar 2016 19:01:40 +0100 Subject: Refactor and rebase #380: Firefox reader view links Fixes #366 Closes #380 --- application/Url.php | 42 +++++++++++++++++++++++++++++------------- tests/Url/UrlTest.php | 7 +++++++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/application/Url.php b/application/Url.php index e7c3a4cc..af38c4d9 100644 --- a/application/Url.php +++ b/application/Url.php @@ -118,24 +118,41 @@ class Url */ public function __construct($url) { - $this->parts = parse_url(trim($url)); + $url = self::cleanupUnparsedUrl(trim($url)); + $this->parts = parse_url($url); if (!empty($url) && empty($this->parts['scheme'])) { $this->parts['scheme'] = 'http'; } } + /** + * Clean up URL before it's parsed. + * ie. handle urlencode, url prefixes, etc. + * + * @param string $url URL to clean. + * + * @return string cleaned URL. + */ + protected static function cleanupUnparsedUrl($url) + { + return self::removeFirefoxAboutReader($url); + } - private function removeFirefoxAboutReader($input){ - $output_array = []; - preg_match("%^about://reader\?url=(.*)%", $input, $output_array); - if(!empty($output_array)){ - $extractedUrl = preg_replace("%^about://reader\?url=(.*)%", "$1", $input); - $url = urldecode($extractedUrl); - }else{ - $url = $input; - } - return $url; + /** + * Remove Firefox Reader prefix if it's present. + * + * @param string $input url + * + * @return string cleaned url + */ + protected static function removeFirefoxAboutReader($input) + { + $firefoxPrefix = 'about://reader?url='; + if (startsWith($input, $firefoxPrefix)) { + return urldecode(ltrim($input, $firefoxPrefix)); + } + return $input; } /** @@ -200,8 +217,7 @@ class Url { $this->cleanupQuery(); $this->cleanupFragment(); - $url = $this->toString(); - return $this->removeFirefoxAboutReader($url); + return $this->toString(); } /** diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php index 425327ed..a64a73ea 100644 --- a/tests/Url/UrlTest.php +++ b/tests/Url/UrlTest.php @@ -128,6 +128,13 @@ class UrlTest extends PHPUnit_Framework_TestCase self::$baseUrl.'?my=stuff&is=kept#again', $url->cleanup() ); + + // test firefox reader url + $url = new Url( + 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') + ); + $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); + } /** -- cgit v1.2.3