aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Url.php32
-rw-r--r--tests/Url/UrlTest.php7
2 files changed, 38 insertions, 1 deletions
diff --git a/application/Url.php b/application/Url.php
index a4ac2e73..af38c4d9 100644
--- a/application/Url.php
+++ b/application/Url.php
@@ -118,7 +118,8 @@ class Url
118 */ 118 */
119 public function __construct($url) 119 public function __construct($url)
120 { 120 {
121 $this->parts = parse_url(trim($url)); 121 $url = self::cleanupUnparsedUrl(trim($url));
122 $this->parts = parse_url($url);
122 123
123 if (!empty($url) && empty($this->parts['scheme'])) { 124 if (!empty($url) && empty($this->parts['scheme'])) {
124 $this->parts['scheme'] = 'http'; 125 $this->parts['scheme'] = 'http';
@@ -126,6 +127,35 @@ class Url
126 } 127 }
127 128
128 /** 129 /**
130 * Clean up URL before it's parsed.
131 * ie. handle urlencode, url prefixes, etc.
132 *
133 * @param string $url URL to clean.
134 *
135 * @return string cleaned URL.
136 */
137 protected static function cleanupUnparsedUrl($url)
138 {
139 return self::removeFirefoxAboutReader($url);
140 }
141
142 /**
143 * Remove Firefox Reader prefix if it's present.
144 *
145 * @param string $input url
146 *
147 * @return string cleaned url
148 */
149 protected static function removeFirefoxAboutReader($input)
150 {
151 $firefoxPrefix = 'about://reader?url=';
152 if (startsWith($input, $firefoxPrefix)) {
153 return urldecode(ltrim($input, $firefoxPrefix));
154 }
155 return $input;
156 }
157
158 /**
129 * Returns a string representation of this URL 159 * Returns a string representation of this URL
130 */ 160 */
131 public function toString() 161 public function 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
128 self::$baseUrl.'?my=stuff&is=kept#again', 128 self::$baseUrl.'?my=stuff&is=kept#again',
129 $url->cleanup() 129 $url->cleanup()
130 ); 130 );
131
132 // test firefox reader url
133 $url = new Url(
134 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept')
135 );
136 $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup());
137
131 } 138 }
132 139
133 /** 140 /**