diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-05-18 14:59:13 +0200 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2025-05-26 20:49:49 +0200 |
commit | 7f48085d1139e3fde128d1bc4c89fcfe9cce571a (patch) | |
tree | 1135d471df125d2247b68ee20f5b52e06694267a | |
parent | 6047cf1f4b52074bab9899c6ef1348332d05d10c (diff) |
Core/Commands: Don't validate enum numeric values for flags
(cherry picked from commit 031fddd2c736055d1f9f389c3a514e14b4562610)
-rw-r--r-- | src/server/game/Chat/ChatCommands/ChatCommandArgs.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h index 9369ed10eda..630e7ea6237 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h @@ -20,6 +20,7 @@ #include "ChatCommandHelpers.h" #include "ChatCommandTags.h" +#include "EnumFlag.h" #include "SmartEnum.h" #include "StringConvert.h" #include "StringFormat.h" @@ -188,16 +189,21 @@ namespace Trinity::Impl::ChatCommands } // Value not found. Try to parse arg as underlying type and cast it to enum type - using U = std::underlying_type_t<T>; - U uVal = 0; - if (ChatCommandResult next2 = ArgInfo<U>::TryConsume(uVal, handler, args)) + do { - if (EnumUtils::IsValid<T>(uVal)) + using U = std::underlying_type_t<T>; + U uVal = 0; + if (ChatCommandResult next2 = ArgInfo<U>::TryConsume(uVal, handler, args)) { + // validate numeric value only if its not a flag to allow combined flags + if constexpr (!EnumTraits::IsFlag<T>::value) + if (!EnumUtils::IsValid<T>(uVal)) + break; + val = static_cast<T>(uVal); return next2; } - } + } while (false); if (next1) return FormatTrinityString(handler, LANG_CMDPARSER_STRING_VALUE_INVALID, STRING_VIEW_FMT_ARG(strVal), Trinity::GetTypeName<T>().c_str()); |