diff src/spellfile.c @ 28790:a161c262e947 v8.2.4919

patch 8.2.4919: can add invalid bytes with :spellgood Commit: https://github.com/vim/vim/commit/7c824682d2028432ee082703ef0ab399867a089b Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 8 22:32:58 2022 +0100 patch 8.2.4919: can add invalid bytes with :spellgood Problem: Can add invalid bytes with :spellgood. Solution: Check for a valid word string.
author Bram Moolenaar <Bram@vim.org>
date Sun, 08 May 2022 23:45:02 +0200
parents 4dcccb2673fe
children f4ff490d51a7
line wrap: on
line diff
--- a/src/spellfile.c
+++ b/src/spellfile.c
@@ -4390,6 +4390,10 @@ store_word(
     int		res = OK;
     char_u	*p;
 
+    // Avoid adding illegal bytes to the word tree.
+    if (enc_utf8 && !utf_valid_string(word, NULL))
+	return FAIL;
+
     (void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
     for (p = pfxlist; res == OK; ++p)
     {
@@ -6190,6 +6194,12 @@ spell_add_word(
     int		i;
     char_u	*spf;
 
+    if (enc_utf8 && !utf_valid_string(word, NULL))
+    {
+	emsg(_(e_illegal_character_in_word));
+	return;
+    }
+
     if (idx == 0)	    // use internal wordlist
     {
 	if (int_wordlist == NULL)