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
This commit is contained in:
Ingo Schommer 2010-11-01 04:53:47 +00:00 committed by Sam Minnee
parent 452a8f8839
commit 09d25b0d70

View File

@ -520,27 +520,39 @@ class Controller extends RequestHandler {
} }
/** /**
* Joins two link segments together, putting a slash between them if necessary. * Joins two or more link segments together, putting a slash between them if necessary.
* Use this for building the results of Link() methods. * Use this for building the results of {@link Link()} methods.
* * If either of the links have query strings,
* If either of the links have query strings, then they will be combined and put at the end of the resulting url. * 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() { static function join_links() {
$args = func_get_args(); $args = func_get_args();
$result = ""; $result = "";
$querystrings = array(); $querystrings = array();
$fragmentIdentifier = null;
foreach($args as $arg) { 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) { if(strpos($arg,'?') !== false) {
list($arg, $suffix) = explode('?',$arg,2); list($arg, $suffix) = explode('?',$arg,2);
$querystrings[] = $suffix; $querystrings[] = $suffix;
} }
if($arg) { if($arg) {
if($result && substr($result,-1) != '/' && $arg[0] != '/') $result .= "/$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($querystrings) $result .= '?' . implode('&', $querystrings);
if($fragmentIdentifier) $result .= "#$fragmentIdentifier";
return $result; return $result;
} }