Skip to content

Commit 62f6135

Browse files
committed
helpers\View: Ensure makeBaseUrl returns absolute URI
This is required by both uses: - RSS controller: RSS feeds are supposed to contain absolute paths - Session: Cookies depend on URI scheme and host If `base_url` was configured to an absolute path reference, not an absolute URI, those would fail.
1 parent 1a1fba1 commit 62f6135

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/helpers/View.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ public function __construct(Configuration $configuration) {
3434
}
3535

3636
/**
37-
* Returns the base url of the page. If a base url was configured in the
38-
* config.ini this will be used. Otherwise base url will be generated by
39-
* globale server variables ($_SERVER).
37+
* Returns the absolute base URL of the page, with path ending with a /.
38+
*
39+
* The returned value depends on the value of the `base_url` option in `config.ini`:
40+
*
41+
* - unset – implicit base URI automatically determined from global server variables ($_SERVER)
42+
* - absolute path – the implicit base URI with path replaced with the configured value
43+
* - absolute URL – the configured value as is
4044
*/
4145
public function getBaseUrl(): Uri {
4246
if ($this->baseUrl === null) {
@@ -49,7 +53,7 @@ public function getBaseUrl(): Uri {
4953
private function makeBaseUrl(): Uri {
5054
$base = $this->configuration->baseUrl;
5155

52-
if ($base !== null) {
56+
if ($base !== null && Uri::isAbsolute($base)) {
5357
// base url in config.ini file
5458
return $base;
5559
}
@@ -87,7 +91,8 @@ private function makeBaseUrl(): Uri {
8791
$port = ':' . $_SERVER['HTTP_X_FORWARDED_PORT'];
8892
}
8993

90-
$base = new Uri($protocol . '://' . $host . $port . $subdir . '/');
94+
$base = (new Uri($protocol . '://' . $host . $port))
95+
->withPath($base !== null ? $base->getPath() : ($subdir . '/'));
9196

9297
return $base;
9398
}

0 commit comments

Comments
 (0)