add another special case for URL parsing, and some tests, see #1236
This commit is contained in:
parent
17c43f62e2
commit
12a8747020
2 changed files with 19 additions and 1 deletions
|
@ -128,6 +128,20 @@ class UrlsTest extends TestCase
|
|||
'http://$SERVER/$INSTALL_DIR/index.php?q=$PATH should return $PATH'
|
||||
);
|
||||
|
||||
// even when we are /test/... publicly, and generating /test/... URLs,
|
||||
// we should still be able to handle URLs at the root because that's
|
||||
// what apache sends us when it is reverse-proxying a subdirectory
|
||||
$this->assertEquals(
|
||||
"tasty/cake",
|
||||
_get_query("/tasty/cake"),
|
||||
'http://$SERVER/$INSTALL_DIR/$PATH should return $PATH'
|
||||
);
|
||||
$this->assertEquals(
|
||||
"tasty/cake",
|
||||
_get_query("/index.php?q=tasty/cake"),
|
||||
'http://$SERVER/$INSTALL_DIR/index.php?q=$PATH should return $PATH'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
"tasty/cake%20pie",
|
||||
_get_query("/test/index.php?q=tasty/cake%20pie"),
|
||||
|
|
|
@ -121,7 +121,7 @@ function _get_query(?string $uri = null): string
|
|||
// if we're looking at http://site.com/$INSTALL_DIR/$PAGE,
|
||||
// then get the query from the path
|
||||
else {
|
||||
$base = get_base_href() . "/";
|
||||
$base = get_base_href();
|
||||
$q = $parsed_url["path"] ?? "";
|
||||
|
||||
// sometimes our public URL is /img/foo/bar but after
|
||||
|
@ -130,6 +130,10 @@ function _get_query(?string $uri = null): string
|
|||
if (str_starts_with($q, $base)) {
|
||||
$q = substr($q, strlen($base));
|
||||
}
|
||||
|
||||
// whether we are /img/foo/bar or /foo/bar, we still
|
||||
// want to remove the leading slash
|
||||
$q = ltrim($q, "/");
|
||||
}
|
||||
|
||||
assert(!str_starts_with($q, "/"));
|
||||
|
|
Reference in a new issue