From 7c824682d2028432ee082703ef0ab399867a089b Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 8 May 2022 22:32:58 +0100 Subject: [PATCH] patch 8.2.4919: can add invalid bytes with :spellgood Problem: Can add invalid bytes with :spellgood. Solution: Check for a valid word string. --- src/errors.h | 4 ++++ src/mbyte.c | 2 +- src/spellfile.c | 10 ++++++++++ src/testdir/test_spell_utf8.vim | 5 +++++ src/version.c | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) From fe978c2b6bb9d897d962595a4a51dd7a71dc8e89 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 8 May 2022 22:43:51 +0100 Subject: [PATCH] patch 8.2.4921: spell test fails because of new illegal byte check Problem: Spell test fails because of new illegal byte check. Solution: Remove the test. --- src/testdir/test_spell.vim | 8 -------- src/version.c | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4047,7 +4047,7 @@ theend: convert_setup(&vimconv, NULL, NULL); } -#if defined(FEAT_GUI_GTK) || defined(PROTO) +#if defined(FEAT_GUI_GTK) || defined(FEAT_SPELL) || defined(PROTO) /* * Return TRUE if string "s" is a valid utf-8 string. * When "end" is NULL stop at the first NUL. --- a/src/spellfile.c +++ b/src/spellfile.c @@ -4361,6 +4361,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(word, len, foldword, MAXWLEN); for (p = pfxlist; res == OK; ++p) { @@ -6167,6 +6171,12 @@ spell_add_word( int i; char_u *spf; + if (enc_utf8 && !utf_valid_string(word, NULL)) + { + emsg(_("E1280: Illegal character in word")); + return; + } + if (idx == 0) /* use internal wordlist */ { if (int_wordlist == NULL) --- a/src/testdir/test_spell.vim +++ b/src/testdir/test_spell.vim @@ -476,16 +476,6 @@ func RunGoodBad(good, bad, expected_word bwipe! endfunc -func Test_spell_single_word() - set spell - new - silent! norm 0R00 - spell! ß - silent 0norm 0r$ Dvz= - set nospell - bwipe! -endfunc - let g:test_data_aff1 = [ \"SET ISO8859-1", \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ", @@ -936,3 +926,8 @@ let g:test_data_aff_sal = [ \"SAL Z S", \ ] +" Invalid bytes may cause trouble when creating the word list. +func Test_check_for_valid_word() + call assert_fails("spellgood! 0\xac", 'E1280:') +endfunc + --- a/src/version.c +++ b/src/version.c @@ -796,6 +796,10 @@ static int included_patches[] = /**/ 5024, /**/ + 4921, +/**/ + 4919, +/**/ 4899, /**/ 4428,