mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
var/www/pages/index.php : filter empty URI parts mid-path
This commit is contained in:
parent
0df931d3ee
commit
f48218397a
1 changed files with 4 additions and 6 deletions
|
@ -36,7 +36,10 @@ if (preg_match("/^\/[a-zA-Z0-9_ +\-\/\.]+\$/", $request_url) != 1) {
|
||||||
|
|
||||||
$git_prefix = "/data/git/gitea-repositories";
|
$git_prefix = "/data/git/gitea-repositories";
|
||||||
$parts = explode("/", $request_url);
|
$parts = explode("/", $request_url);
|
||||||
array_shift($parts); # remove empty first
|
|
||||||
|
# Remove empty first, potentially empty parts between //. If URL ends on "/", last entry in array is empty too. Remove it:
|
||||||
|
$parts = array_filter($parts, function($p) { return strlen($p) > 0; });
|
||||||
|
|
||||||
$owner = strtolower(array_shift($parts));
|
$owner = strtolower(array_shift($parts));
|
||||||
$git_root = realpath("$git_prefix/$owner/pages.git");
|
$git_root = realpath("$git_prefix/$owner/pages.git");
|
||||||
|
|
||||||
|
@ -45,11 +48,6 @@ if (substr($git_root, 0, strlen($git_prefix)) !== $git_prefix) {
|
||||||
send_response(404, "this user/organization does not have codeberg pages");
|
send_response(404, "this user/organization does not have codeberg pages");
|
||||||
}
|
}
|
||||||
|
|
||||||
# If URL ends on "/", last entry in array is empty. Remove it:
|
|
||||||
if (end($parts) === "") {
|
|
||||||
array_pop($parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
$file_url = implode("/", $parts);
|
$file_url = implode("/", $parts);
|
||||||
|
|
||||||
# If this is a folder or just empty, we add 'index.html' to the URL:
|
# If this is a folder or just empty, we add 'index.html' to the URL:
|
||||||
|
|
Loading…
Reference in a new issue