Skip to content

Commit

Permalink
Router::url should passthru //example.com/file.ext
Browse files Browse the repository at this point in the history
The function allows ://example.com/file.ext but was treating //example.com as cake-relative URL. The updated regex matches URI schemes as defined in RFC2396. Will passthru any of these formats:
* Starts with a valid URI scheme  (javascript:, https:, itunes:, ftp:)
* Starts with a '#'
* [NEW] Starts with a '?' which may be meaningless, but is as valid as starting with '#' (RFC1808)
* starts with //, or :// (:// is not technically valid, but included for compatibilty)
  • Loading branch information
HaroldPutman committed Jun 21, 2013
1 parent cfdac5e commit 2fd36bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -870,7 +870,7 @@ public static function url($url = null, $full = false) {
$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) === '/') {
Expand Down
7 changes: 7 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -2555,6 +2555,9 @@ public function testUrlProtocol() {
$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));

Expand All @@ -2566,6 +2569,10 @@ public function testUrlProtocol() {

$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));
Expand Down

0 comments on commit 2fd36bd

Please sign in to comment.