mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-25 19:26:21 +00:00
fix(tools): implement backslash escaping for contact names
Implement backslash based escaping in the command parser and autocompletion logic to handle contact names containing double quotes. This stops the parser from splitting nicknames into multiple tokens, which previously caused "Invalid usage" errors. The parser now sees \ as an escape character for quotes and spaces in _parse_args_helper, count_tokens and get_start. Autocomplete results are escaped when they contain spaces, and search prefixes are unescaped before matching. strip_arg_quotes() has also been updated to handle unescaping. Fixes: https://github.com/profanity-im/profanity/issues/1844 Signed-off-by: Michael Vetter <jubalh@iodoru.org>
This commit is contained in:
@@ -234,7 +234,16 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote,
|
||||
FREE_SET_NULL(ac->search_str);
|
||||
}
|
||||
|
||||
ac->search_str = strdup(search_str);
|
||||
// unescape search string
|
||||
GString* unescaped = g_string_new("");
|
||||
for (const char* p = search_str; *p; p++) {
|
||||
if (*p == '\\' && (*(p + 1) == '"' || *(p + 1) == '\\')) {
|
||||
p++;
|
||||
}
|
||||
g_string_append_c(unescaped, *p);
|
||||
}
|
||||
ac->search_str = g_string_free(unescaped, FALSE);
|
||||
|
||||
found = _search(ac, ac->items, quote, NEXT);
|
||||
|
||||
return found;
|
||||
@@ -403,7 +412,15 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction
|
||||
|
||||
// if contains space, quote before returning
|
||||
if (quote && g_strrstr(curr->data, " ")) {
|
||||
return g_strdup_printf("\"%s\"", (gchar*)curr->data);
|
||||
GString* escaped = g_string_new("\"");
|
||||
for (const char* p = curr->data; *p; p++) {
|
||||
if (*p == '"' || *p == '\\') {
|
||||
g_string_append_c(escaped, '\\');
|
||||
}
|
||||
g_string_append_c(escaped, *p);
|
||||
}
|
||||
g_string_append_c(escaped, '"');
|
||||
return g_string_free(escaped, FALSE);
|
||||
// otherwise just return the string
|
||||
} else {
|
||||
return strdup(curr->data);
|
||||
|
||||
Reference in New Issue
Block a user