From d33cffdb2e195be118d99342aa42f1d15a186f27 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 3 Sep 2020 18:46:10 +0200 Subject: [PATCH] Fix: encoding in legacy route login redirection to post bookmark When a bookmark is post from a logged out user, he is first redirected to the login page with 'returnurl' containing the link, then redirected again when the login is processed. We need to reencode the posted URL, otherwise the browser does not handle the fragment as a part of the posted parameter. --- application/legacy/LegacyController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php index e16dd0f4..826604e7 100644 --- a/application/legacy/LegacyController.php +++ b/application/legacy/LegacyController.php @@ -39,13 +39,23 @@ public function process(Request $request, Response $response, string $action): R /** Legacy route: ?post= */ public function post(Request $request, Response $response): Response { - $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; $route = '/admin/shaare'; + $buildParameters = function (?array $parameters, bool $encode) { + if ($encode) { + $parameters = array_map('urlencode', $parameters); + } + + return count($parameters) > 0 ? '?' . http_build_query($parameters) : ''; + }; + if (!$this->container->loginManager->isLoggedIn()) { + $parameters = $buildParameters($request->getQueryParams(), true); return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); } + $parameters = $buildParameters($request->getQueryParams(), false); + return $this->redirect($response, $route . $parameters); }