From 2664ed2ee451bba6db210f12e6b40d2632f77e98 Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 17 Jul 2007 13:45:20 +0000 Subject: [PATCH] Fixing trailing slash in URL when extension is used (Ticket #2934) git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5439 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 3 +++ cake/tests/cases/libs/router.test.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/cake/libs/router.php b/cake/libs/router.php index 7111aab2c..7d638b01e 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -601,6 +601,9 @@ class Router extends Object { if ($full) { $output = FULL_BASE_URL . $output; } + if(!empty($extension) && substr($output, -1) == '/') { + $output = substr($output, 0, -1); + } return $output . $extension . $_this->queryString($q) . $frag; } /** diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 3f2e5fb0d..9f4db125d 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -158,6 +158,12 @@ class RouterTest extends UnitTestCase { $this->assertEqual($result, $expected); } + function testUrlGenerationWithExtensions() { + $result = $this->router->url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'id' => null, 'ext' => 'json')); + $expected = '/articles/add.json'; + $this->assertEqual($result, $expected); + } + function testPluginUrlGeneration() { $this->router->setRequestInfo(array( array(