From 169a36a450a2c5c3a9d49a2bd75e22b0788696cd Mon Sep 17 00:00:00 2001 From: Cloud-Kid <49484832+Cloud-Kid@users.noreply.github.com> Date: Mon, 11 May 2026 11:22:33 +0200 Subject: [PATCH] Normalize DEB distribution aliases --- www/controllers/Task/Form/Form.php | 13 ++++++-- www/controllers/Task/Form/Param/Dist.php | 39 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/www/controllers/Task/Form/Form.php b/www/controllers/Task/Form/Form.php index 110ecf275..b1e995050 100644 --- a/www/controllers/Task/Form/Form.php +++ b/www/controllers/Task/Form/Form.php @@ -116,9 +116,9 @@ public function get(string $action, array $repos) : string * Validate the task form filled by the user * @param array $tasksParams */ - public function validate(array $tasksParams) : void + public function validate(array &$tasksParams) : void { - foreach ($tasksParams as $task) { + foreach ($tasksParams as &$task) { /** * Retrieve action */ @@ -149,11 +149,20 @@ public function validate(array $tasksParams) : void throw new Exception('Invalid action: ' . $task['action']); } + /** + * Normalize known DEB distribution aliases before validation and task execution. + */ + if ($task['action'] == 'create' and ($task['package-type'] ?? '') == 'deb' and !empty($task['dist'])) { + $task['dist'] = Param\Dist::normalize($task['dist']); + } + /** * Validate form by calling the controller */ $controller = new $controllerPath(); $controller->validate($task); } + + unset($task); } } diff --git a/www/controllers/Task/Form/Param/Dist.php b/www/controllers/Task/Form/Param/Dist.php index 1e77993fe..8f76feb82 100644 --- a/www/controllers/Task/Form/Param/Dist.php +++ b/www/controllers/Task/Form/Param/Dist.php @@ -7,6 +7,21 @@ class Dist { + /** + * Normalize known distribution aliases to their canonical codenames. + */ + public static function normalize(array $dists) : array + { + $normalizedDists = []; + $aliases = self::aliases(); + + foreach ($dists as $dist) { + $normalizedDists[] = $aliases[strtolower(trim($dist))] ?? $dist; + } + + return array_values(array_unique($normalizedDists)); + } + public static function check(array $dists) : void { if (empty($dists)) { @@ -19,4 +34,28 @@ public static function check(array $dists) : void } } } + + /** + * Build aliases from configured DEB distributions. + */ + private static function aliases() : array + { + $aliases = []; + + foreach (DEB_DISTRIBUTIONS as $distributionName => $distributionDescription) { + $name = strtolower($distributionName); + $description = strtolower($distributionDescription); + $aliases[$name] = $distributionName; + $aliases[$description] = $distributionName; + + if (preg_match('/^(?[a-z]+)\s+(?[0-9]+(?:\.[0-9]+)?)/i', $distributionDescription, $matches)) { + $version = strtolower($matches['version']); + $family = strtolower($matches['family']); + $aliases[$version] = $distributionName; + $aliases[$family . ' ' . $version] = $distributionName; + } + } + + return $aliases; + } }