add another test for self url, split regex into two parts - one for plugins, one for everything else

This commit is contained in:
Andrew Dolgov
2024-09-15 07:17:48 +03:00
parent 9c44af354f
commit 0163884ef6
2 changed files with 14 additions and 1 deletions

View File

@@ -490,7 +490,8 @@ class Config {
$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("/(\/api\/{1,}|\/plugins(.local)?\/.{1,}\/{1,})?(\w+\.php)?(\?.*$)?$/", "", $self_url_path);
$self_url_path = preg_replace("/(\/api\/{1,})?(\w+\.php)?(\?.*$)?$/", "", $self_url_path);
$self_url_path = preg_replace("/(\/plugins(.local))\/.{1,}$/", "", $self_url_path);
return rtrim($self_url_path, "/");
}

View File

@@ -116,6 +116,18 @@ final class SelfUrlPathTest extends TestCase {
);
}
public function test_self_url_j(): void {
$_SERVER = [];
$_SERVER["HTTP_HOST"] = "example.com";
$_SERVER["REQUEST_URI"] = "/tt-rss/plugins.local/example/api/longpath/test.php/reader/api/0/stream/items/ids?n=1000&output=json&s=user/-/state/com.google/starred";
$this->assertEquals(
'http://example.com/tt-rss',
Config::get_self_url(true)
);
}
public function test_get_self_dir(): void {
$this->assertEquals(
dirname(__DIR__), # we're in (app)/tests/