From 000222ae89349ee248fad8e19372e426a984bfa0 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 26 Sep 2024 14:50:47 +0200 Subject: [PATCH] LSurl::public_url: fix handling public root URL with a trailing slash --- src/includes/class/class.LSurl.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/includes/class/class.LSurl.php b/src/includes/class/class.LSurl.php index 7ba64e82..207d7ee4 100644 --- a/src/includes/class/class.LSurl.php +++ b/src/includes/class/class.LSurl.php @@ -192,13 +192,24 @@ class LSurl extends LSlog_staticLoggerClass { $public_root_url = LSconfig :: get('public_root_url', '/', 'string'); if ($absolute && $public_root_url[0] == '/') { - self :: log_debug("LSurl :: public_root_url(absolute=true): configured public root URL is relative ($public_root_url) => try to detect it from current request infos."); - $public_root_url = 'http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'').'://'.$_SERVER['HTTP_HOST'].$public_root_url; - self :: log_debug("LSurl :: public_root_url(absolute=true): detected public absolute root URL: $public_root_url"); + self :: log_debug( + "LSurl :: public_root_url(absolute=true): configured public root URL is relative ". + "($public_root_url) => try to detect it from current request infos." + ); + $public_root_url = sprintf( + "http%s://%s%s", + isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'?'s':'', + $_SERVER['HTTP_HOST'], + $public_root_url + ); + self :: log_debug( + "LSurl :: public_root_url(absolute=true): detected public absolute root URL: ". + $public_root_url + ); } if ($relative_url) { - if ($public_root_url[0] == '/') $public_root_url .= "/"; + if ($public_root_url[-1] != '/') $public_root_url .= "/"; return $public_root_url.$relative_url; }