summaryrefslogtreecommitdiffstats
path: root/inc/util.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2025-11-26 10:46:51 +0100
committerSimon Rettberg2025-12-12 15:16:59 +0100
commit7c173411785f959d250d3dfbd7d4cfcb0e20f0e0 (patch)
tree242157791a76afb7af23ec2cd3d22b599e54ce9d /inc/util.inc.php
parent[exams] Fix incorrect count() clause (diff)
downloadslx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.gz
slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.xz
slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.zip
Add tests using PHPUnit
Tests generated by Junie AI. Might not have the best possible quality but at least we got something, and if it turns out to be complete rubbish, we can just throw it out again without any issues, as this is independent of the actual code base.
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r--inc/util.inc.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 003da9fa..9fc1320c 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -130,8 +130,14 @@ class Util
return Dictionary::number((float)$bytes, $decimals) . "\xe2\x80\x89" . ($sz[$factor + $shift] ?? '#>PiB#');
}
+ /**
+ * Make sure given string is a valid filename, by replacing sequences of non-ASCII/printable
+ * characters by underscore.
+ */
public static function sanitizeFilename(string $name): string
{
+ if (empty($name))
+ return '_';
return preg_replace('/[^a-zA-Z0-9_\-]+/', '_', $name);
}
@@ -491,7 +497,7 @@ class Util
if (!Property::get('webinterface.redirect-domain') || empty(Property::get('webinterface.https-domains')))
return null; // Disabled, or unknown domain
$curDomain = $_SERVER['HTTP_HOST'];
- if ($curDomain[-1] === '.') {
+ while ($curDomain[-1] === '.') {
$curDomain = substr($curDomain, 0, -1);
}
$domains = explode(' ', Property::get('webinterface.https-domains'));