From c1c7973b955da647374ef3643c3ac21ae26ff00a Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Sun, 11 Oct 2009 00:07:15 +0000 Subject: [PATCH] BUGFIX: Fixed Controller::join_links() to properly handle multiple consecutive slashes. From: Andrew Short git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88494 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Controller.php | 2 +- tests/ControllerTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) mode change 100644 => 100755 tests/ControllerTest.php diff --git a/core/control/Controller.php b/core/control/Controller.php index ae0e9865f..3e69b5877 100755 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -559,7 +559,7 @@ class Controller extends RequestHandler { } if($arg) { if($result && substr($result,-1) != '/' && $arg[0] != '/') $result .= "/$arg"; - else $result .= $arg; + else $result .= (substr($result, -1) == '/' && $arg[0] == '/') ? ltrim($arg, '/') : $arg; } } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php old mode 100644 new mode 100755 index f14cb7b2f..c7b0438ce --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -96,6 +96,12 @@ class ControllerTest extends FunctionalTest { /* Note, however, that it doesn't deal with duplicates very well. */ $this->assertEquals("admin/crm?flush=1&flush=1", Controller::join_links("admin/crm?flush=1", "?flush=1")); + + $this->assertEquals ( + 'admin/action', Controller::join_links('admin/', '/', '/action'), 'Test that multiple slashes are trimmed.' + ); + + $this->assertEquals('/admin/action', Controller::join_links('/admin', 'action')); } }