Improve error reporting for `value=null` in `{plural}` template function
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 12 Apr 2023 09:17:04 +0000 (11:17 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 12 Apr 2023 09:17:04 +0000 (11:17 +0200)
Accidental `null`s are a common issue when dealing with database objects,
explicitly detect a `null` to not misleadingly report that the `value`
attribute is missing.

see https://www.woltlab.com/community/thread/299515-fatal-error-nach-update-missing-attribute-value/

wcfsetup/install/files/lib/system/template/plugin/PluralFunctionTemplatePlugin.class.php

index 9c3fcab8e1c8d3c7cb15855905ea9a0ea6b9a0ae..5b5796262827293acfdb5f2e55976191f38b9eec 100644 (file)
@@ -41,7 +41,11 @@ final class PluralFunctionTemplatePlugin implements IFunctionTemplatePlugin
     public function execute($tagArgs, TemplateEngine $tplObj)
     {
         if (!isset($tagArgs['value'])) {
-            throw new SystemException("Missing attribute 'value'");
+            if (!\array_key_exists('value', $tagArgs)) {
+                throw new SystemException("Missing attribute 'value'");
+            } else {
+                throw new SystemException("Attribute 'value' must not be null");
+            }
         }
         if (!isset($tagArgs['other'])) {
             throw new SystemException("Missing attribute 'other'");