Merge pull request #522 from ArthurHoaro/hotfix/readershaare

Refactor and rebase #380: Firefox reader view links
This commit is contained in:
VirtualTam 2016-03-30 19:31:19 +02:00
commit 11609d9fd8
2 changed files with 38 additions and 1 deletions

View file

@ -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
*/

View file

@ -128,6 +128,13 @@ public function testCleanupMixedContent()
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());
}
/**