Merge pull request #1368 from planardothum/url-conformance

Url conformance
This commit is contained in:
Mark Story 2013-06-27 06:31:42 -07:00
commit 6fdbdf508f
4 changed files with 15 additions and 4 deletions

View file

@ -870,7 +870,7 @@ class Router {
$output = self::_handleNoRoute($url); $output = self::_handleNoRoute($url);
} }
} else { } else {
if (preg_match('/:\/\/|^(javascript|mailto|tel|sms):|^\#/i', $url)) { if (preg_match('/^([a-z][a-z0-9.+\-]+:|:?\/\/|[#?])/i', $url)) {
return $url; return $url;
} }
if (substr($url, 0, 1) === '/') { if (substr($url, 0, 1) === '/') {
@ -888,7 +888,7 @@ class Router {
$output .= Inflector::underscore($params['controller']) . '/' . $url; $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) { if ($protocol === 0) {
$output = str_replace('//', '/', $base . '/' . $output); $output = str_replace('//', '/', $base . '/' . $output);

View file

@ -2555,6 +2555,9 @@ class RouterTest extends CakeTestCase {
$url = '://example.com'; $url = '://example.com';
$this->assertEquals($url, Router::url($url)); $this->assertEquals($url, Router::url($url));
$url = '//example.com';
$this->assertEquals($url, Router::url($url));
$url = 'javascript:void(0)'; $url = 'javascript:void(0)';
$this->assertEquals($url, Router::url($url)); $this->assertEquals($url, Router::url($url));
@ -2566,6 +2569,10 @@ class RouterTest extends CakeTestCase {
$url = '#here'; $url = '#here';
$this->assertEquals($url, Router::url($url)); $this->assertEquals($url, Router::url($url));
$url = '?param=0';
$this->assertEquals($url, Router::url($url));
$url = 'posts/index#here'; $url = 'posts/index#here';
$expected = FULL_BASE_URL . '/posts/index#here'; $expected = FULL_BASE_URL . '/posts/index#here';
$this->assertEquals($expected, Router::url($url, true)); $this->assertEquals($expected, Router::url($url, true));

View file

@ -660,6 +660,9 @@ class HelperTest extends CakeTestCase {
$result = $this->Helper->assetUrl('foo.jpg?one=two&three=four'); $result = $this->Helper->assetUrl('foo.jpg?one=two&three=four');
$this->assertEquals('foo.jpg?one=two&three=four', $result); $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', 'here' => '/cake_dev/index.php/tasks',
)); ));
$result = $this->Helper->assetUrl('img/cake.icon.png', array('fullBase' => true)); $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');
} }
/** /**

View file

@ -341,7 +341,7 @@ class Helper extends Object {
*/ */
protected function _encodeUrl($url) { protected function _encodeUrl($url) {
$path = parse_url($url, PHP_URL_PATH); $path = parse_url($url, PHP_URL_PATH);
$parts = array_map('urldecode', explode('/', $path)); $parts = array_map('rawurldecode', explode('/', $path));
$parts = array_map('rawurlencode', $parts); $parts = array_map('rawurlencode', $parts);
$encoded = implode('/', $parts); $encoded = implode('/', $parts);
return h(str_replace($path, $encoded, $url)); return h(str_replace($path, $encoded, $url));