diff options
| author | Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> | 2022-05-18 06:40:51 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-05-18 06:40:51 +0000 |
| commit | f452fa8039361590ea31ac1c206d777fdcf147af (patch) | |
| tree | 94f1c9916009c1e1fc3c03cd01a5b60cf5bbe955 /app/controllers/studip_controller.php | |
| parent | 2b4aea3189f0906e078da36c0fd3349126ced997 (diff) | |
fix behaviour of `url_for` with fragments, fixes #985
Closes #985
Merge request studip/studip!630
Diffstat (limited to 'app/controllers/studip_controller.php')
| -rw-r--r-- | app/controllers/studip_controller.php | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/app/controllers/studip_controller.php b/app/controllers/studip_controller.php index 5cdb3de..cad182a 100644 --- a/app/controllers/studip_controller.php +++ b/app/controllers/studip_controller.php @@ -275,6 +275,11 @@ abstract class StudipController extends Trails_Controller throw new InvalidArgumentException(__METHOD__ . ' cannot be used with absolute URLs'); } + // Extract fragment (if any) + if (strpos($to, '#') !== false) { + list($args[0], $fragment) = explode('#', $to); + } + // Extract parameters (if any) $params = []; if (is_array(end($args))) { @@ -289,17 +294,9 @@ abstract class StudipController extends Trails_Controller return $arg; }, $args); - // Combine arguments to new $to string - $to = implode('/', $args); - - //preserve fragment - $to_parts = explode('#', $to); - $to = $to_parts[0]; - $fragment = $to_parts[1] ?? ''; - - $url = parent::url_for($to); + $url = parent::url_for(...$args); - if ($fragment) { + if (isset($fragment)) { $url .= '#' . $fragment; } return URLHelper::getURL($url, $params); |
