From d4e1516071711b0ff3f0327214564aea426cd0d3 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Wed, 14 Aug 2019 22:37:13 +0200
Subject: [PATCH] Fix Locale; If a Twig-variable is not set and then
 translated, these methods are called with a null parameter

---
 lib/SimpleSAML/Locale/Translate.php | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php
index b706b99c8..1a03e2772 100644
--- a/lib/SimpleSAML/Locale/Translate.php
+++ b/lib/SimpleSAML/Locale/Translate.php
@@ -399,12 +399,15 @@ class Translate
     /**
      * Translate a singular text.
      *
-     * @param string $original The string before translation.
+     * @param string|null $original The string before translation.
      *
      * @return string The translated string.
      */
-    public static function translateSingularGettext(string $original): string
+    public static function translateSingularGettext(?string $original): string
     {
+        // This may happen if you forget to set a variable and then run undefinedVar through the trans-filter
+        $original = $original ?? 'undefined variable';
+
         $text = BaseTranslator::$current->gettext($original);
 
         if (func_num_args() === 1 || $original === null) {
@@ -420,14 +423,17 @@ class Translate
     /**
      * Translate a plural text.
      *
-     * @param string $original The string before translation.
+     * @param string|null $original The string before translation.
      * @param string $plural
      * @param string $value
      *
      * @return string The translated string.
      */
-    public static function translatePluralGettext(string $original, string $plural, string $value): string
+    public static function translatePluralGettext(?string $original, string $plural, string $value): string
     {
+        // This may happen if you forget to set a variable and then run undefinedVar through the trans-filter
+        $original = $original ?? 'undefined variable';
+
         $text = BaseTranslator::$current->ngettext($original, $plural, $value);
 
         if (func_num_args() === 3) {
-- 
GitLab