Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/ILIAS/UICore/classes/class.ilCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
class ilCtrl implements ilCtrlInterface
{
use ilCtrlNamespaceEncoding;

protected ?object $exec_object = null;
protected ?string $command = null;

Expand Down Expand Up @@ -868,7 +870,7 @@ private function getTargetUrl(
$target_url = $this->appendParameterString(
$target_url,
self::PARAM_BASE_CLASS,
urlencode($base_class), // encode in case of namespaced classes
$this->encodeNamespaceForUrl($base_class), // encode in case of namespaced classes
$is_escaped
);

Expand All @@ -889,7 +891,7 @@ private function getTargetUrl(
$target_url = $this->appendParameterString(
$target_url,
self::PARAM_CMD_CLASS,
urlencode($cmd_class), // encode in case of namespaced classes
$this->encodeNamespaceForUrl($cmd_class), // encode in case of namespaced classes
$is_escaped
);
}
Expand Down
6 changes: 4 additions & 2 deletions components/ILIAS/UICore/classes/class.ilCtrlContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/
class ilCtrlContext implements ilCtrlContextInterface
{
use ilCtrlNamespaceEncoding;

/**
* @var ilCtrlPathFactory
*/
Expand Down Expand Up @@ -305,14 +307,14 @@ protected function adoptRequestParameters(): void
// previously set existing path.
$base_class = $this->getQueryParam(ilCtrlInterface::PARAM_BASE_CLASS);
if (null !== $base_class) {
$this->setBaseClass($base_class);
$this->setBaseClass($this->decodeNamespaceFromUrl($base_class));
}

// set or append the provided command class, which might
// override the previously set path again.
$cmd_class = $this->getQueryParam(ilCtrlInterface::PARAM_CMD_CLASS);
if (null !== $cmd_class) {
$this->setCmdClass($cmd_class);
$this->setCmdClass($this->decodeNamespaceFromUrl($cmd_class));
}
}

Expand Down
46 changes: 46 additions & 0 deletions components/ILIAS/UICore/classes/trait.ilCtrlNamespaceEncoding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

declare(strict_types=1);

/**
* This absolute monstrosity of an encoding/decoding trait exists because
* ILIAS strips `\` from request URLs. This prevents ilCtrl from using
* PSR-4 namespaced command- and base-classes until we either work around
* this issue or drop these as arguments from the URL – which we could, but
* decide not to pursue, because we should focus on migrating towards a
* real routing component (see https://docu.ilias.de/go/wiki/wpage_8780_1357).
*
* @author Thibeau Fuhrer <thibeau@sr.solutions>
*
* @noinspection AutoloadingIssuesInspection
*/
trait ilCtrlNamespaceEncoding
{
private static string $psr4_namespace_delimiter = '\\';
private static string $ilctrl_namespace_delimiter = '.';

public function encodeNamespaceForUrl(string $psr4_namespace): string
{
return str_replace(self::$psr4_namespace_delimiter, self::$ilctrl_namespace_delimiter, $psr4_namespace);
}

public function decodeNamespaceFromUrl(string $ilctrl_namespace): string
{
return str_replace(self::$ilctrl_namespace_delimiter, self::$psr4_namespace_delimiter, $ilctrl_namespace);
}
}
Loading