From 3e2a85b7f5a7a2d8736af5211ec41b69b1080f7a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 19 Jul 2017 17:23:22 +0200 Subject: [PATCH] Only throw an exception for empty arrays while devtools are active See #2338 --- .../util/PreparedStatementConditionBuilder.class.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php b/wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php index d4273878ac..0a884cccf0 100644 --- a/wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php +++ b/wcfsetup/install/files/lib/system/database/util/PreparedStatementConditionBuilder.class.php @@ -31,11 +31,18 @@ class PreparedStatementConditionBuilder extends ConditionBuilder { 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."'"); + // Only throw an exception if the developer tools are active, preventing this + // from triggering an error for queries that are never actually executed. + // + // This is done to preserve backwards-compatibility with earlier releases that + // allowed this kind of issue, effectively relying on the database to bail out. + if (ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS) { + throw new \RuntimeException("An empty array was passed for token number " . ($count + 1) . " in condition '" . $condition . "'"); + } } $result = '?'; - if (is_array($parameters[$count])) { + if (is_array($parameters[$count]) && !empty($parameters[$count])) { $result .= str_repeat(',?', count($parameters[$count]) - 1); } -- 2.20.1