summaryrefslogtreecommitdiff
path: root/src/plugins/trigger
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-02-13 18:44:43 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-13 18:44:43 +0100
commit0ac6ebe5328072e49d1776cecde8e45650c471e4 (patch)
tree36dd31ca6705bf6fadd6991b5feafde8af338017 /src/plugins/trigger
parentc06cfb25ce1fb36894fd0902aef728eba179d850 (diff)
downloadweechat-0ac6ebe5328072e49d1776cecde8e45650c471e4.zip
trigger: escape chars in regex replacement (when trigger is created)
Diffstat (limited to 'src/plugins/trigger')
-rw-r--r--src/plugins/trigger/trigger-callback.c9
-rw-r--r--src/plugins/trigger/trigger.c17
-rw-r--r--src/plugins/trigger/trigger.h1
3 files changed, 19 insertions, 8 deletions
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index 2910f3a6e..c114c118d 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -199,10 +199,11 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
continue;
}
- replace_eval = weechat_string_eval_expression (trigger->regex[i].replace,
- pointers,
- extra_vars,
- NULL);
+ replace_eval = weechat_string_eval_expression (
+ trigger->regex[i].replace_escaped,
+ pointers,
+ extra_vars,
+ NULL);
if (replace_eval)
{
value = weechat_string_replace_regex (ptr_value,
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index b9bc1bbef..16233a24d 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -466,6 +466,8 @@ trigger_free_regex (int *regex_count, struct t_trigger_regex **regex)
}
if ((*regex)[i].replace)
free ((*regex)[i].replace);
+ if ((*regex)[i].replace_escaped)
+ free ((*regex)[i].replace_escaped);
}
free (*regex);
*regex = NULL;
@@ -554,6 +556,7 @@ trigger_split_regex (const char *trigger_name, const char *str_regex,
(*regex)[index].str_regex = NULL;
(*regex)[index].regex = NULL;
(*regex)[index].replace = NULL;
+ (*regex)[index].replace_escaped = NULL;
/* set string with regex */
(*regex)[index].str_regex = weechat_strndup (ptr_regex,
@@ -585,6 +588,10 @@ trigger_split_regex (const char *trigger_name, const char *str_regex,
strdup (pos_replace + length_delimiter);
if (!(*regex)[index].replace)
goto memory_error;
+ (*regex)[index].replace_escaped =
+ weechat_string_convert_escaped_chars ((*regex)[index].replace);
+ if (!(*regex)[index].replace_escaped)
+ goto memory_error;
if (!pos_replace_end)
break;
@@ -1061,14 +1068,16 @@ trigger_print_log ()
weechat_log_printf (" regex . . . . . . . . . : 0x%lx", ptr_trigger->regex);
for (i = 0; i < ptr_trigger->regex_count; i++)
{
- weechat_log_printf (" regex[%03d].variable . . : '%s'",
+ weechat_log_printf (" regex[%03d].variable . . . : '%s'",
i, ptr_trigger->regex[i].variable);
- weechat_log_printf (" regex[%03d].str_regex. . : '%s'",
+ weechat_log_printf (" regex[%03d].str_regex. . . : '%s'",
i, ptr_trigger->regex[i].str_regex);
- weechat_log_printf (" regex[%03d].regex. . . . : 0x%lx",
+ weechat_log_printf (" regex[%03d].regex. . . . . : 0x%lx",
i, ptr_trigger->regex[i].regex);
- weechat_log_printf (" regex[%03d].replace. . . : '%s'",
+ weechat_log_printf (" regex[%03d].replace. . . . : '%s'",
i, ptr_trigger->regex[i].replace);
+ weechat_log_printf (" regex[%03d].replace_escaped: '%s'",
+ i, ptr_trigger->regex[i].replace_escaped);
}
weechat_log_printf (" commands_count. . . . . : %d", ptr_trigger->commands_count);
weechat_log_printf (" commands. . . . . . . . : 0x%lx", ptr_trigger->commands);
diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h
index 978947d04..d60f13ee7 100644
--- a/src/plugins/trigger/trigger.h
+++ b/src/plugins/trigger/trigger.h
@@ -72,6 +72,7 @@ struct t_trigger_regex
char *str_regex; /* regex to search for replacement */
regex_t *regex; /* compiled regex */
char *replace; /* replacement text */
+ char *replace_escaped; /* repl. text (with chars escaped) */
};
struct t_trigger