[core] fixes and tests for get_base_href + get_query, see #1024

This commit is contained in:
Shish
2024-02-07 22:47:12 +00:00
parent c6e65a21f9
commit 7adb7348d7
6 changed files with 95 additions and 21 deletions

View File

@@ -715,19 +715,33 @@ function _get_user(): User
function _get_query(): string
{
// if query is explicitly set, use it
$q = @$_POST["q"] ?: @$_GET["q"];
if(!empty($q)) {
return $q;
// if q is set in POST, use that
if(isset($_POST["q"])) {
return $_POST["q"];
}
// if q is set in GET, use that
// (we need to manually parse the query string because PHP's $_GET
// does an extra round of URL decoding, which we don't want)
$parts = parse_url($_SERVER['REQUEST_URI']);
$qs = [];
foreach(explode('&', $parts['query'] ?? "") as $z) {
$qps = explode('=', $z, 2);
if(count($qps) == 2) {
$qs[$qps[0]] = $qps[1];
}
}
if(isset($qs["q"])) {
return $qs["q"];
}
// if we're just looking at index.php, use the default query
elseif (str_contains($_SERVER['REQUEST_URI'], "index.php")) {
if(str_ends_with($parts["path"], "index.php")) {
return "/";
}
// otherwise, use the request URI
else {
return explode("?", $_SERVER['REQUEST_URI'])[0];
}
return $parts["path"];
}