Skip to content

Commit

Permalink
Fix extensions always being defaulted.
Browse files Browse the repository at this point in the history
Extensions should not magically be defaulted. Doing this makes
generating URLs unpredictable and annoying.

Refs #4771
  • Loading branch information
markstory committed Oct 1, 2014
1 parent fc79553 commit 5cddb90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Routing/Router.php
Expand Up @@ -517,7 +517,7 @@ public static function url($url = null, $full = false) {
'plugin' => null,
'controller' => null,
'action' => 'index',
'_ext' => null
'_ext' => null,
);
$here = $base = $output = $frag = null;

Expand Down Expand Up @@ -575,7 +575,7 @@ public static function url($url = null, $full = false) {
'plugin' => $params['plugin'],
'controller' => $params['controller'],
'action' => 'index',
'_ext' => $params['_ext']
'_ext' => null
);
}

Expand Down
32 changes: 32 additions & 0 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -1035,6 +1035,38 @@ public function testUrlGenerationWithExtensions() {
$this->assertEquals($expected, $result);
}

/**
* test url() when the current request has an extension.
*
* @return void
*/
public function testUrlGenerationWithExtensionInCurrentRequest() {
Router::extensions('rss');
Router::scope('/', function ($r) {
$r->fallbacks();
});
$request = new Request();
$request->addParams(['controller' => 'Tasks', 'action' => 'index', '_ext' => 'rss']);
Router::pushRequest($request);

$result = Router::url(array(
'controller' => 'Tasks',
'action' => 'view',
1
));
$expected = '/tasks/view/1';
$this->assertEquals($expected, $result);

$result = Router::url(array(
'controller' => 'Tasks',
'action' => 'view',
1,
'_ext' => 'json'
));
$expected = '/tasks/view/1.json';
$this->assertEquals($expected, $result);
}

/**
* Test url generation with named routes.
*/
Expand Down

0 comments on commit 5cddb90

Please sign in to comment.