Patch 8.2.4919

11 views
Skip to first unread message

Bram Moolenaar

unread,
May 8, 2022, 5:33:36 PM5/8/22
to vim...@googlegroups.com

Patch 8.2.4919
Problem: Can add invalid bytes with :spellgood.
Solution: Check for a valid word string.
Files: src/mbyte.c, src/spellfile.c, src/errors.h,
src/testdir/test_spell_utf8.vim


*** ../vim-8.2.4918/src/mbyte.c 2022-04-11 15:28:45.824940910 +0100
--- src/mbyte.c 2022-05-08 22:05:18.636845635 +0100
***************
*** 4226,4232 ****
convert_setup(&vimconv, NULL, NULL);
}

! #if defined(FEAT_GUI_GTK) || defined(PROTO)
/*
* Return TRUE if string "s" is a valid utf-8 string.
* When "end" is NULL stop at the first NUL.
--- 4226,4232 ----
convert_setup(&vimconv, NULL, NULL);
}

! #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.
*** ../vim-8.2.4918/src/spellfile.c 2022-04-15 13:53:30.056708670 +0100
--- src/spellfile.c 2022-05-08 22:17:57.344425958 +0100
***************
*** 4390,4395 ****
--- 4390,4399 ----
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,6195 ****
--- 6194,6205 ----
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)
*** ../vim-8.2.4918/src/errors.h 2022-05-06 16:18:37.125781978 +0100
--- src/errors.h 2022-05-08 22:18:32.648407340 +0100
***************
*** 3273,3275 ****
--- 3273,3279 ----
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
*** ../vim-8.2.4918/src/testdir/test_spell_utf8.vim 2021-10-06 13:41:03.592314063 +0100
--- src/testdir/test_spell_utf8.vim 2022-05-08 22:32:12.695616629 +0100
***************
*** 780,784 ****
--- 780,789 ----
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
*** ../vim-8.2.4918/src/version.c 2022-05-08 21:25:17.125880347 +0100
--- src/version.c 2022-05-08 22:09:16.472708543 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4919,
/**/

--
I wish there was a knob on the TV to turn up the intelligence.
There's a knob called "brightness", but it doesn't seem to work.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages