diff options
| author | Simon Rettberg | 2025-11-26 10:46:51 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-12-12 15:16:59 +0100 |
| commit | 7c173411785f959d250d3dfbd7d4cfcb0e20f0e0 (patch) | |
| tree | 242157791a76afb7af23ec2cd3d22b599e54ce9d /inc | |
| parent | [exams] Fix incorrect count() clause (diff) | |
| download | slx-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')
| -rw-r--r-- | inc/arrayutil.inc.php | 2 | ||||
| -rw-r--r-- | inc/paginate.inc.php | 2 | ||||
| -rw-r--r-- | inc/user.inc.php | 2 | ||||
| -rw-r--r-- | inc/util.inc.php | 8 |
4 files changed, 10 insertions, 4 deletions
diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php index 3d93d7d5..ff44b914 100644 --- a/inc/arrayutil.inc.php +++ b/inc/arrayutil.inc.php @@ -8,6 +8,8 @@ class ArrayUtil /** * Take an array of arrays, take given key from each sub-array and return * new array with just those corresponding values. + * If a key is missing from one of the sub-arrays, the entry will be skipped, + * and the resulting array will have fewer entries than the input array. */ public static function flattenByKey(array $list, string $key): array { diff --git a/inc/paginate.inc.php b/inc/paginate.inc.php index 806e2f41..aaafe030 100644 --- a/inc/paginate.inc.php +++ b/inc/paginate.inc.php @@ -47,7 +47,7 @@ class Paginate } // Mangle URL if ($url === null) { - $url = $_SERVER['REQUEST_URI']; + $url = $_SERVER['REQUEST_URI'] ?? ''; } if (strpos($url, '?') === false) { $url .= '?'; diff --git a/inc/user.inc.php b/inc/user.inc.php index 088f12c6..ff367a7f 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -4,8 +4,6 @@ declare(strict_types=1); use JetBrains\PhpStorm\NoReturn; -require_once('inc/session.inc.php'); - class User { 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')); |
