diff options
author | Andrew Dolgov <[email protected]> | 2023-10-24 22:27:27 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-10-24 22:27:27 +0300 |
commit | 69c1c629927cd78286fc6c8d61b5b5ad78245508 (patch) | |
tree | 01cf192af1d71f6406aed02e492749f70d96d4c8 /classes | |
parent | de2830b241dc393695fe9278d431d412c1be6266 (diff) |
add a workaround for make_self_url() when invoked off /api/ endpoint, add unit tests for this method
Diffstat (limited to 'classes')
-rw-r--r-- | classes/config.php | 6 |
1 files changed, 3 insertions, 3 deletions
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); |