core: do not remove quotes in arguments of command /eval (closes #1601)

Now, /eval -n -c "a" == "a" returns True instead of False.

When quotes were removed, the condition evaluated was: a" == "a (which is
False).
This commit is contained in:
Sébastien Helleu 2020-12-25 00:21:03 +01:00
parent a8abfcd7b4
commit ee9aa28a8c
3 changed files with 28 additions and 30 deletions

View File

@ -28,6 +28,7 @@ New features::
Bug fixes::
* core: do not remove quotes in arguments of command /eval as they can be part of the evaluated expression/condition (issue #1601)
* core: display an error when the buffer is not found with command /command -buffer
* exec: fix search of command by identifier
* irc: fix completion of commands /halfop and /dehalfop

View File

@ -2023,7 +2023,7 @@ COMMAND_CALLBACK(debug)
COMMAND_CALLBACK(eval)
{
int i, print_only, split_command, condition, debug, error;
char *result, *ptr_args, *expr, **commands;
char *result, *ptr_args, **commands;
const char **debug_output;
struct t_hashtable *pointers, *options;
@ -2103,36 +2103,31 @@ COMMAND_CALLBACK(eval)
if (print_only)
{
expr = string_remove_quotes (ptr_args, "\"");
if (expr)
result = eval_expression (ptr_args, pointers, NULL, options);
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t>> %s", ptr_args);
if (result)
{
result = eval_expression (expr, pointers, NULL, options);
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t>> %s", ptr_args);
if (result)
{
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t== %s[%s%s%s]",
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
result,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
free (result);
}
else
{
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t== %s<%s%s%s>",
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
_("error"),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
}
free (expr);
if (options && debug)
{
debug_output = hashtable_get (options,
"debug_output");
if (debug_output)
gui_chat_printf (NULL, "%s", debug_output);
}
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t== %s[%s%s%s]",
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
result,
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
free (result);
}
else
{
gui_chat_printf_date_tags (NULL, 0, "no_log", "\t== %s<%s%s%s>",
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
_("error"),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS));
}
if (options && debug)
{
debug_output = hashtable_get (options,
"debug_output");
if (debug_output)
gui_chat_printf (NULL, "%s", debug_output);
}
}
else

View File

@ -203,6 +203,8 @@ TEST(CoreEval, EvalCondition)
WEE_CHECK_EVAL("1", "-0xA3 < 2");
WEE_CHECK_EVAL("1", "1 == 18 > 5");
WEE_CHECK_EVAL("1", "abc == abc");
WEE_CHECK_EVAL("1", "'abc' == 'abc'");
WEE_CHECK_EVAL("1", "\"abc\" == \"abc\"");
WEE_CHECK_EVAL("1", "(26 > 5)");
WEE_CHECK_EVAL("1", "((26 > 5))");
WEE_CHECK_EVAL("1", "(5 < 26)");