Permalink
Browse files

Fixed bug where Dispatcher::getUrl() returned incorrect URL if $base …

…appeared in a $uri besides at start of $uri.
  • Loading branch information...
1 parent d5fb0b2 commit b567de977e6d1e570095f26ae1eb1eaccbb6cb78 @ADmad ADmad committed Nov 23, 2010
Showing with 18 additions and 11 deletions.
  1. +4 −4 cake/dispatcher.php
  2. +14 −7 cake/tests/cases/dispatcher.test.php
View
@@ -82,7 +82,7 @@ function __construct($url = null, $base = false) {
}
/**
- * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the
+ * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the
* results (if autoRender is set).
*
* If no controller of given name can be found, invoke() shows error messages in
@@ -483,8 +483,8 @@ function getUrl($uri = null, $base = null) {
if ($tmpUri === '/' || $tmpUri == $baseDir || $tmpUri == $base) {
$url = $_GET['url'] = '/';
} else {
- if ($base && strpos($uri, $base) !== false) {
- $elements = explode($base, $uri);
+ if ($base && strpos($uri, $base) === 0) {
+ $elements = explode($base, $uri, 2);
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
} else {
@@ -560,7 +560,7 @@ function asset($url) {
}
$filters = Configure::read('Asset.filter');
$isCss = (
- strpos($url, 'ccss/') === 0 ||
+ strpos($url, 'ccss/') === 0 ||
preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i', $url)
);
$isJs = (
@@ -1017,6 +1017,13 @@ function testGetUrl() {
$expected = '?/home';
$this->assertEqual($expected, $result);
+ $_GET['url'] = array();
+ $Dispatcher =& new Dispatcher();
+ $Dispatcher->base = '/shop';
+ $uri = '/shop/fr/pages/shop';
+ $result = $Dispatcher->getUrl($uri);
+ $expected = 'fr/pages/shop';
+ $this->assertEqual($expected, $result);
}
/**
@@ -1367,11 +1374,11 @@ function testDispatch() {
$url = 'test_dispatch_pages/camelCased';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual('TestDispatchPages', $controller->name);
-
+
$url = 'test_dispatch_pages/camelCased/something. .';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
-
+
}
/**
@@ -1395,7 +1402,7 @@ function testDispatchWithArray() {
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs);
-
+
$this->assertEqual($Dispatcher->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->here);
}
@@ -1441,7 +1448,7 @@ function testPluginDispatch() {
Router::reload();
$Dispatcher =& new TestDispatcher();
Router::connect(
- '/my_plugin/:controller/*',
+ '/my_plugin/:controller/*',
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
);
@@ -1598,7 +1605,7 @@ function testAutomaticPluginControllerDispatch() {
'action' => 'admin_index',
'prefix' => 'admin',
'admin' => true,
- 'form' => array(),
+ 'form' => array(),
'url' => array('url' => 'admin/articles_test'),
'return' => 1
);
@@ -1980,7 +1987,7 @@ function testMissingAssetProcessor404() {
}
/**
- * test that asset filters work for theme and plugin assets
+ * test that asset filters work for theme and plugin assets
*
* @return void
*/
@@ -2008,7 +2015,7 @@ function testAssetFilterForThemeAndPlugins() {
$Dispatcher->stopped = false;
$Dispatcher->asset('css/ccss/debug_kit.css');
$this->assertFalse($Dispatcher->stopped);
-
+
$Dispatcher->stopped = false;
$Dispatcher->asset('js/cjs/debug_kit.js');
$this->assertFalse($Dispatcher->stopped);

0 comments on commit b567de9

Please sign in to comment.