Navigation Menu

Skip to content

Commit

Permalink
patch 8.2.4919: can add invalid bytes with :spellgood
Browse files Browse the repository at this point in the history
Problem:    Can add invalid bytes with :spellgood.
Solution:   Check for a valid word string.
  • Loading branch information
brammool committed May 8, 2022
1 parent 9830db6 commit 7c82468
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/errors.h
Expand Up @@ -3273,3 +3273,7 @@ EXTERN char e_stray_closing_curly_str[]
EXTERN char e_missing_close_curly_str[]
INIT(= N_("E1279: Missing '}': %s"));
#endif
#ifdef FEAT_SPELL
EXTERN char e_illegal_character_in_word[]
INIT(= N_("E1280: Illegal character in word"));
#endif
2 changes: 1 addition & 1 deletion src/mbyte.c
Expand Up @@ -4226,7 +4226,7 @@ utf_find_illegal(void)
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.
Expand Down
10 changes: 10 additions & 0 deletions src/spellfile.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/testdir/test_spell_utf8.vim
Expand Up @@ -780,5 +780,10 @@ func Test_no_crash_with_weird_text()
bwipe!
endfunc

" Invalid bytes may cause trouble when creating the word list.
func Test_check_for_valid_word()
call assert_fails("spellgood! 0\xac", 'E1280:')
endfunc


" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4919,
/**/
4918,
/**/
Expand Down

0 comments on commit 7c82468

Please sign in to comment.