Refactor and rebase #380: Firefox reader view links
Fixes #366 Closes #380
This commit is contained in:
parent
ecd051905f
commit
c9da01e749
2 changed files with 36 additions and 13 deletions
|
@ -118,24 +118,41 @@ class Url
|
||||||
*/
|
*/
|
||||||
public function __construct($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'])) {
|
if (!empty($url) && empty($this->parts['scheme'])) {
|
||||||
$this->parts['scheme'] = 'http';
|
$this->parts['scheme'] = 'http';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private function removeFirefoxAboutReader($input){
|
* Clean up URL before it's parsed.
|
||||||
$output_array = [];
|
* ie. handle urlencode, url prefixes, etc.
|
||||||
preg_match("%^about://reader\?url=(.*)%", $input, $output_array);
|
*
|
||||||
if(!empty($output_array)){
|
* @param string $url URL to clean.
|
||||||
$extractedUrl = preg_replace("%^about://reader\?url=(.*)%", "$1", $input);
|
*
|
||||||
$url = urldecode($extractedUrl);
|
* @return string cleaned URL.
|
||||||
}else{
|
*/
|
||||||
$url = $input;
|
protected static function cleanupUnparsedUrl($url)
|
||||||
|
{
|
||||||
|
return self::removeFirefoxAboutReader($url);
|
||||||
}
|
}
|
||||||
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 @@ public function cleanup()
|
||||||
{
|
{
|
||||||
$this->cleanupQuery();
|
$this->cleanupQuery();
|
||||||
$this->cleanupFragment();
|
$this->cleanupFragment();
|
||||||
$url = $this->toString();
|
return $this->toString();
|
||||||
return $this->removeFirefoxAboutReader($url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -128,6 +128,13 @@ public function testCleanupMixedContent()
|
||||||
self::$baseUrl.'?my=stuff&is=kept#again',
|
self::$baseUrl.'?my=stuff&is=kept#again',
|
||||||
$url->cleanup()
|
$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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue