]> jfr.im git - irc/weechat/weechat.git/commitdiff
spell: properly skip WeeChat color codes when checking words in input (closes #1547)
authorSébastien Helleu <redacted>
Sat, 22 Aug 2020 06:56:21 +0000 (08:56 +0200)
committerSébastien Helleu <redacted>
Sat, 22 Aug 2020 06:56:21 +0000 (08:56 +0200)
ChangeLog.adoc
src/plugins/spell/spell.c

index 22d317ce3599695bff3e9fc6c75ee5123b5102dc..89e392c5ca1aa99bc7fe5c2651c53a26881ec516 100644 (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)
 
index e260f11644b7b137ee80d804f3280131440f394e..905864019ef85921786da001c417dbd04ae3c00f 100644 (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;