aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
authorGravatar Inverle <inverle@proton.me> 2025-08-30 16:26:24 +0200
committerGravatar GitHub <noreply@github.com> 2025-08-30 16:26:24 +0200
commit379a387ddeabdab428c2c6257ff6521f69e5d974 (patch)
treebbd3e517d3bb42a7fd8b7b9170a4ad335abc5c86 /lib/Minz
parent43248b461d4f7b74fe0ab761259ef29e4b0636c6 (diff)
Disallow setting non-existent language (#7878)
The set language is used inside paths and can lead to issues by including PHP files from other locations
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/Translate.php5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index 58bf3f424..b57e90bcf 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -84,6 +84,10 @@ class Minz_Translate {
return array_values(array_unique($list_langs));
}
+ public static function exists(string $lang): bool {
+ return in_array($lang, Minz_Translate::availableLanguages(), true);
+ }
+
/**
* Return the language to use in the application.
* It returns the connected language if it exists then returns the first match from the
@@ -95,6 +99,7 @@ class Minz_Translate {
*/
public static function getLanguage(?string $user, array $preferred, ?string $default): string {
if (null !== $user) {
+ if (!self::exists($user)) return 'en';
return $user;
}