From 5c8369ce38c67fba7dd39d68626534c7e61eb24c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 29 Jul 2024 14:48:17 +0200 Subject: Strong type array parameter helper (#6661) Also useful for extensions (including one I am writing) --- app/Controllers/entryController.php | 2 +- lib/Minz/Request.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 9104cefc4..8cea74752 100644 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -114,7 +114,7 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController { } } else { /** @var array $idArray */ - $idArray = Minz_Request::paramArray('id'); + $idArray = Minz_Request::paramArrayString('id'); $idString = Minz_Request::paramString('id'); if (count($idArray) > 0) { $ids = $idArray; diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 301bd5623..8121eb104 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -69,6 +69,15 @@ class Minz_Request { return $specialchars ? Minz_Helper::htmlspecialchars_utf8(self::$params[$key]) : self::$params[$key]; } + /** @return array */ + public static function paramArrayString(string $key, bool $specialchars = false): array { + if (empty(self::$params[$key]) || !is_array(self::$params[$key])) { + return []; + } + $result = array_filter(self::$params[$key], 'is_string'); + return $specialchars ? Minz_Helper::htmlspecialchars_utf8($result) : $result; + } + public static function paramTernary(string $key): ?bool { if (isset(self::$params[$key])) { $p = self::$params[$key]; -- cgit v1.2.3