Changed the regex to follow the RFC 3986, working to protocols like "svn+ssh://" and "ed2k://"

This commit is contained in:
Juan Basso 2010-11-03 01:26:41 -02:00
parent b752766d6c
commit adb2d90b9a
2 changed files with 17 additions and 1 deletions

View file

@ -831,7 +831,7 @@ class Router {
$output .= Inflector::underscore($params['controller']) . '/' . $url;
}
}
$protocol = preg_match('#^[a-z]+\://#', $output);
$protocol = preg_match('#^[a-z][a-z0-9+-.]*\://#i', $output);
if ($protocol === 0) {
$output = str_replace('//', '/', $base . '/' . $output);

View file

@ -2248,4 +2248,20 @@ class RouterTest extends CakeTestCase {
$this->assertEquals($url, $result);
}
/**
* test protocol in url
*
* @return void
*/
public function testUrlProtocol() {
$url = 'http://example.com';
$this->assertEqual($url, Router::url($url));
$url = 'ed2k://example.com';
$this->assertEqual($url, Router::url($url));
$url = 'svn+ssh://example.com';
$this->assertEqual($url, Router::url($url));
}
}