From 69c1c629927cd78286fc6c8d61b5b5ad78245508 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 24 Oct 2023 22:27:27 +0300 Subject: add a workaround for make_self_url() when invoked off /api/ endpoint, add unit tests for this method --- classes/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'classes/config.php') diff --git a/classes/config.php b/classes/config.php index 17c555fa9..72d6c5106 100644 --- a/classes/config.php +++ b/classes/config.php @@ -479,14 +479,14 @@ class Config { /** returns fully-qualified external URL to tt-rss (no trailing slash) * SELF_URL_PATH configuration variable is used as a fallback for the CLI SAPI * */ - static function get_self_url() : string { - if (php_sapi_name() == "cli") { + static function get_self_url(bool $always_detect = false) : string { + if (!$always_detect && php_sapi_name() == "cli") { return self::get(Config::SELF_URL_PATH); } else { $proto = self::is_server_https() ? 'https' : 'http'; $self_url_path = $proto . '://' . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); - $self_url_path = preg_replace("/\w+\.php(\?.*$)?$/", "", $self_url_path); + $self_url_path = preg_replace("/(\/api\/{1,})?(\w+\.php)?(\?.*$)?$/", "", $self_url_path); if (substr($self_url_path, -1) === "/") { return substr($self_url_path, 0, -1); -- cgit v1.2.3