Throw an exception when condition parameter is an empty array
authorAlexander Ebert <ebert@woltlab.com>
Fri, 14 Jul 2017 16:19:42 +0000 (18:19 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 14 Jul 2017 16:19:42 +0000 (18:19 +0200)
See #2338

wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php

index 1bd16d8607b3fcbf953986ee4cec9bbfc0c1d169..d4273878ac85d4cb6c9e3f5b5398bbffb69819a7 100644 (file)
@@ -26,13 +26,16 @@ class PreparedStatementConditionBuilder extends ConditionBuilder {
        public function add($condition, array $parameters = []) {
                if (!empty($parameters)) {
                        $count = 0;
-                       $callback = function ($matches) use (&$count, $parameters, $condition) {
+                       $callback = function () use (&$count, $parameters, $condition) {
                                if (!array_key_exists($count, $parameters)) {
                                        throw new SystemException("missing parameter for token number " . ($count + 1) . " in condition '".$condition."'");
                                }
+                               else if (is_array($parameters[$count]) && empty($parameters[$count])) {
+                                       throw new \RuntimeException("An empty array was passed for token number " . ($count + 1) . " in condition '".$condition."'");
+                               }
                                
                                $result = '?';
-                               if (is_array($parameters[$count]) && !empty($parameters[$count])) {
+                               if (is_array($parameters[$count])) {
                                        $result .= str_repeat(',?', count($parameters[$count]) - 1);
                                }