From f4af532c5a8f37f69035616e2ae7908bf5b77a62 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 13 Mar 2022 19:37:45 +0100 Subject: Trim trailing & from query_string. When trying to fetch an image file from the Cloud module, the default nginx config will add a trailing & if there's no args specified. Example: https://example.com/cloud/username/some_image.png This will be rewritten to: https://example.com/index.php?q=/cloud/username/some_image.png& This in turn will cause the Cloud module to try to redirect back to the original because it does not match the query_string (in which the ampersand has been converted to a question mark). And this will repeat until the browser get's tired of it. --- boot.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'boot.php') diff --git a/boot.php b/boot.php index 5fa314eee..42b162506 100644 --- a/boot.php +++ b/boot.php @@ -915,9 +915,14 @@ class App { if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { self::$query_string = str_replace(['<', '>'], ['<', '>'], substr($_SERVER['QUERY_STRING'], 2)); + // removing trailing / - maybe a nginx problem if (substr(self::$query_string, 0, 1) == "/") self::$query_string = substr(self::$query_string, 1); + + // trim trailing '&' if no extra args are present + self::$query_string = rtrim(self::$query_string, '&'); + // change the first & to ? self::$query_string = preg_replace('/&/', '?', self::$query_string, 1); } -- cgit v1.2.3