spell: properly skip WeeChat color codes when checking words in input (closes #1547)

This commit is contained in:
Sébastien Helleu 2020-08-22 08:56:21 +02:00
parent 268aa631c6
commit b459dab84b
2 changed files with 23 additions and 1 deletions

View File

@ -31,6 +31,7 @@ Bug fixes::
* core: set "notify_level" to 3 if there is a highlight in the line (issue #1529)
* core: do not add line with highlight and tag "notify_none" to hotlist (issue #1529)
* irc: send all channels in a single JOIN command when reconnecting to the server (issue #1551)
* spell: properly skip WeeChat color codes when checking words in input (issue #1547)
* trigger: fix recursive calls to triggers using regex (issue #1546)
* trigger: add `${tg_tags} !!- ,notify_none,` in conditions of default trigger "beep" (issue #1529)

View File

@ -656,7 +656,7 @@ spell_modifier_cb (const void *pointer, void *data,
char *misspelled_word, *old_misspelled_word, *old_suggestions, *suggestions;
char *word_and_suggestions;
const char *color_normal, *color_error, *ptr_suggestions, *pos_colon;
int code_point, char_size;
int code_point, char_size, color_code_size;
int length, index_result, length_word, word_ok;
int length_color_normal, length_color_error, rc;
int input_pos, current_pos, word_start_pos, word_end_pos, word_end_pos_valid;
@ -782,12 +782,33 @@ spell_modifier_cb (const void *pointer, void *data,
{
ptr_string_orig = NULL;
/* skip color codes */
while ((color_code_size = weechat_string_color_code_size (ptr_string)) > 0)
{
memcpy (result + index_result, ptr_string, color_code_size);
index_result += color_code_size;
ptr_string += color_code_size;
}
if (!ptr_string[0])
break;
/* find start of word: it must start with an alphanumeric char */
code_point = weechat_utf8_char_int (ptr_string);
while ((!iswalnum (code_point)) || iswspace (code_point))
{
/* skip color codes */
while ((color_code_size = weechat_string_color_code_size (ptr_string)) > 0)
{
memcpy (result + index_result, ptr_string, color_code_size);
index_result += color_code_size;
ptr_string += color_code_size;
}
if (!ptr_string[0])
break;
if (!ptr_string_orig && !iswspace (code_point))
ptr_string_orig = ptr_string;
char_size = weechat_utf8_char_size (ptr_string);
memcpy (result + index_result, ptr_string, char_size);
index_result += char_size;