From d11cb0f2c291ae0197922c695145e59103f28425 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 16 Jul 2002 16:20:10 +0000 Subject: [PATCH] '\' characters in nicks were skipped when sending messages in queries. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2867 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/misc.c | 16 ++++++++++++++++ src/core/misc.h | 3 +++ src/fe-common/core/chat-completion.c | 6 ++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 6bf87177..01ae0f1d 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -770,3 +770,19 @@ int expand_escape(const char **data) return strtol(digit, NULL, 8); } } + +/* Escape all '"', "'" and '\' chars with '\' */ +char *escape_string(const char *str) +{ + char *ret, *p; + + p = ret = g_malloc(strlen(str)*2+1); + while (*str != '\0') { + if (*str == '"' || *str == '\'' || *str == '\\') + *p++ = '\\'; + *p++ = *str++; + } + *p = '\0'; + + return ret; +} diff --git a/src/core/misc.h b/src/core/misc.h index 804cffc2..b9002c1c 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -105,4 +105,7 @@ GSList *columns_sort_list(GSList *list, int rows); one after '\'. Returns the expanded character or -1 if error. */ int expand_escape(const char **data); +/* Escape all '"', "'" and '\' chars with '\' */ +char *escape_string(const char *str); + #endif diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c index c70f7e5b..a5a4287b 100644 --- a/src/fe-common/core/chat-completion.c +++ b/src/fe-common/core/chat-completion.c @@ -928,7 +928,7 @@ static char *auto_complete(CHANNEL_REC *channel, const char *line) static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { - char *line, *str; + char *line, *str, *target; g_return_if_fail(data != NULL); @@ -956,9 +956,11 @@ static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item) /* the nick is quoted in case it contains '-' character. also spaces should work too now :) Unquoter function also allows '"' characters as long as the next character isn't space. */ + target = escape_string(window_item_get_target(item)); str = g_strdup_printf(IS_CHANNEL(item) ? "-channel \"%s\" %s" : IS_QUERY(item) ? "-nick \"%s\" %s" : "%s %s", - window_item_get_target(item), line); + target, line); + g_free(target); signal_emit("command msg", 3, str, server, item);