diff --git a/core/control/Controller.php b/core/control/Controller.php index ec60da71d..65691bb60 100755 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -558,7 +558,13 @@ class Controller extends RequestHandler { $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; @@ -570,6 +576,7 @@ class Controller extends RequestHandler { } if($querystrings) $result .= '?' . implode('&', $querystrings); + if($fragmentIdentifier) $result .= "#$fragmentIdentifier"; return $result; } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index cb697624d..48581fa8a 100755 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -102,6 +102,12 @@ class ControllerTest extends FunctionalTest { ); $this->assertEquals('/admin/action', Controller::join_links('/admin', 'action')); + + /* One fragment identifier is handled as you would expect */ + $this->assertEquals("my-page?arg=var#subsection", Controller::join_links("my-page#subsection", "?arg=var")); + + /* If there are multiple, it takes the last one */ + $this->assertEquals("my-page?arg=var#second-section", Controller::join_links("my-page#subsection", "?arg=var", "#second-section")); } /**