diff --git a/core/polyfills.php b/core/polyfills.php index 08e7a01c..d9dc50ac 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -308,9 +308,10 @@ function get_base_href(): string } if(str_ends_with($_SERVER['PHP_SELF'], 'index.php')) { $self = $_SERVER['PHP_SELF']; - } - elseif(isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['DOCUMENT_ROOT'])) { + } elseif(isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['DOCUMENT_ROOT'])) { $self = substr($_SERVER['SCRIPT_FILENAME'], strlen(rtrim($_SERVER['DOCUMENT_ROOT'], "/"))); + } else { + die("PHP_SELF or SCRIPT_FILENAME need to be set"); } $dir = dirname($self); $dir = str_replace("\\", "/", $dir); diff --git a/core/tests/PolyfillsTest.php b/core/tests/PolyfillsTest.php index aa43c4da..91fe64e1 100644 --- a/core/tests/PolyfillsTest.php +++ b/core/tests/PolyfillsTest.php @@ -255,6 +255,9 @@ class PolyfillsTest extends TestCase $this->assertFalse(file_exists($dir)); } + /** + * @param array $vars + */ private function _tbh(array $vars, string $result): void { // update $_SERVER with $vars, call get_base_href() and check result, then reset $_SERVER to original value diff --git a/core/util.php b/core/util.php index cbdaead7..67a3403c 100644 --- a/core/util.php +++ b/core/util.php @@ -736,12 +736,12 @@ function _get_query(): string } // if we're just looking at index.php, use the default query - if(str_ends_with($parts["path"], "index.php")) { + if(str_ends_with($parts["path"] ?? "", "index.php")) { return "/"; } // otherwise, use the request URI minus the base path - return substr($parts["path"], strlen(get_base_href())); + return substr($parts["path"] ?? "", strlen(get_base_href())); }