Check strings against '' instead of using empty when validating in DBO actions
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 2 Jul 2020 14:32:12 +0000 (16:32 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 2 Jul 2020 14:33:43 +0000 (16:33 +0200)
`empty('0')` will return true, despite the string not actually being empty
which is undesired.

Fixes WoltLab/com.woltlab.wbb#387

wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php

index 510268aed87863d4a7437ed7ae3265a3454c7b6d..49a17d2bb1db7b55c56927ffd7c3bd0856b322eb 100644 (file)
@@ -563,7 +563,7 @@ abstract class AbstractDatabaseObjectAction implements IDatabaseObjectAction, ID
                                else {
                                        if ($structure === self::STRUCT_FLAT) {
                                                $target[$variableName] = StringUtil::trim($target[$variableName]);
-                                               if (!$allowEmpty && empty($target[$variableName])) {
+                                               if (!$allowEmpty && $target[$variableName] === '') {
                                                        throw new UserInputException($variableName);
                                                }
                                        }
@@ -574,7 +574,7 @@ abstract class AbstractDatabaseObjectAction implements IDatabaseObjectAction, ID
                                                }
                                                
                                                for ($i = 0, $length = count($target[$variableName]); $i < $length; $i++) {
-                                                       if (empty($target[$variableName][$i])) {
+                                                       if ($target[$variableName][$i] === '') {
                                                                throw new UserInputException($variableName);
                                                        }
                                                }