From: VirtualTam Date: Wed, 30 Mar 2016 17:31:19 +0000 (+0200) Subject: Merge pull request #522 from ArthurHoaro/hotfix/readershaare X-Git-Tag: v0.7.0~20 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=11609d9fd8ba53f049e6c913d8e3affab6cfc9ce;hp=5f143b72eaafeda533fcb997ecca73d38258546e;p=github%2Fshaarli%2FShaarli.git Merge pull request #522 from ArthurHoaro/hotfix/readershaare Refactor and rebase #380: Firefox reader view links --- diff --git a/application/Url.php b/application/Url.php index a4ac2e73..af38c4d9 100644 --- a/application/Url.php +++ b/application/Url.php @@ -118,13 +118,43 @@ 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); + } + + /** + * 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; + } + /** * Returns a string representation of this URL */ 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()); + } /**