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 d173a18 commit 390a7ae59c1711799b113edcd6ed36b75fb54fe6 @ADmad ADmad committed Nov 23, 2010
Showing with 11 additions and 4 deletions.
  1. +2 −2 cake/dispatcher.php
  2. +9 −2 cake/tests/cases/dispatcher.test.php
View
@@ -552,8 +552,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 {
@@ -956,6 +956,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);
}
/**
* testBaseUrlAndWebrootWithModRewrite method
@@ -1296,11 +1303,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');
-
+
}
/**
* testDispatchWithArray method

0 comments on commit 390a7ae

Please sign in to comment.