diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 029a949e1..bdba40a45 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -870,7 +870,7 @@ class Router { $output = self::_handleNoRoute($url); } } else { - if (preg_match('/:\/\/|^(javascript|mailto|tel|sms):|^\#/i', $url)) { + if (preg_match('/^([a-z][a-z0-9.+\-]+:|:?\/\/|[#?])/i', $url)) { return $url; } if (substr($url, 0, 1) === '/') { @@ -888,7 +888,7 @@ class Router { $output .= Inflector::underscore($params['controller']) . '/' . $url; } } - $protocol = preg_match('#^[a-z][a-z0-9+-.]*\://#i', $output); + $protocol = preg_match('#^[a-z][a-z0-9+\-.]*\://#i', $output); if ($protocol === 0) { $output = str_replace('//', '/', $base . '/' . $output); diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 449a76fab..d5379e536 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -2555,6 +2555,9 @@ class RouterTest extends CakeTestCase { $url = '://example.com'; $this->assertEquals($url, Router::url($url)); + $url = '//example.com'; + $this->assertEquals($url, Router::url($url)); + $url = 'javascript:void(0)'; $this->assertEquals($url, Router::url($url)); @@ -2566,6 +2569,10 @@ class RouterTest extends CakeTestCase { $url = '#here'; $this->assertEquals($url, Router::url($url)); + + $url = '?param=0'; + $this->assertEquals($url, Router::url($url)); + $url = 'posts/index#here'; $expected = FULL_BASE_URL . '/posts/index#here'; $this->assertEquals($expected, Router::url($url, true)); diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 564b6dc20..9e0a795c7 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -660,6 +660,9 @@ class HelperTest extends CakeTestCase { $result = $this->Helper->assetUrl('foo.jpg?one=two&three=four'); $this->assertEquals('foo.jpg?one=two&three=four', $result); + + $result = $this->Helper->assetUrl('dir/big+tall/image', array('ext' => '.jpg')); + $this->assertEquals('dir/big%2Btall/image.jpg', $result); } /** @@ -674,7 +677,8 @@ class HelperTest extends CakeTestCase { 'here' => '/cake_dev/index.php/tasks', )); $result = $this->Helper->assetUrl('img/cake.icon.png', array('fullBase' => true)); - $this->assertEquals('http://localhost/cake_dev/app/webroot/img/cake.icon.png', $result); + + $this->assertEquals($result, FULL_BASE_URL . '/cake_dev/app/webroot/img/cake.icon.png'); } /** diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 847f5d841..52f779601 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -341,7 +341,7 @@ class Helper extends Object { */ protected function _encodeUrl($url) { $path = parse_url($url, PHP_URL_PATH); - $parts = array_map('urldecode', explode('/', $path)); + $parts = array_map('rawurldecode', explode('/', $path)); $parts = array_map('rawurlencode', $parts); $encoded = implode('/', $parts); return h(str_replace($path, $encoded, $url));