From 09d25b0d70ac1be0ca964b7fec9bf7aa52e240d5 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 1 Nov 2010 04:53:47 +0000 Subject: [PATCH] BUGFIX: Fixed Controller::join_links() handling of fragment identifiers (merged from r104580) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@113319 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Controller.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/control/Controller.php b/core/control/Controller.php index ab2886bb7..4cb8d6ba8 100644 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -520,27 +520,39 @@ class Controller extends RequestHandler { } /** - * Joins two link segments together, putting a slash between them if necessary. - * Use this for building the results of Link() methods. - * - * If either of the links have query strings, then they will be combined and put at the end of the resulting url. + * Joins two or more link segments together, putting a slash between them if necessary. + * Use this for building the results of {@link Link()} methods. + * If either of the links have query strings, + * then they will be combined and put at the end of the resulting url. + * + * Caution: All parameters are expected to be URI-encoded already. + * + * @param String + * @return String */ static function join_links() { $args = func_get_args(); $result = ""; $querystrings = array(); + $fragmentIdentifier = null; foreach($args as $arg) { + // Find fragment identifier - keep the last one + if(strpos($arg,'#') !== false) { + list($arg, $fragmentIdentifier) = explode('#',$arg,2); + } + // Find querystrings if(strpos($arg,'?') !== false) { list($arg, $suffix) = explode('?',$arg,2); $querystrings[] = $suffix; } if($arg) { if($result && substr($result,-1) != '/' && $arg[0] != '/') $result .= "/$arg"; - else $result .= $arg; + else $result .= (substr($result, -1) == '/' && $arg[0] == '/') ? ltrim($arg, '/') : $arg; } } if($querystrings) $result .= '?' . implode('&', $querystrings); + if($fragmentIdentifier) $result .= "#$fragmentIdentifier"; return $result; }