Skip to content

Commit

Permalink
patch 8.2.3846: no error when using control character for 'lcs' or 'fcs'
Browse files Browse the repository at this point in the history
Problem:    No error when using control character for 'lcs' or 'fcs'.
Solution:   Use char2cells() to check the width. (closes #9369)
  • Loading branch information
zeertzjq authored and brammool committed Dec 18, 2021
1 parent 0dc4d8e commit 60618c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/screen.c
Expand Up @@ -4914,19 +4914,19 @@ set_chars_option(win_T *wp, char_u **varp)
c2 = c3 = 0;
s = p + len + 1;
c1 = get_encoded_char_adv(&s);
if (mb_char2cells(c1) > 1)
if (char2cells(c1) > 1)
return e_invarg;
if (tab[i].cp == &lcs_chars.tab2)
{
if (*s == NUL)
return e_invarg;
c2 = get_encoded_char_adv(&s);
if (mb_char2cells(c2) > 1)
if (char2cells(c2) > 1)
return e_invarg;
if (!(*s == ',' || *s == NUL))
{
c3 = get_encoded_char_adv(&s);
if (mb_char2cells(c3) > 1)
if (char2cells(c3) > 1)
return e_invarg;
}
}
Expand Down Expand Up @@ -4968,7 +4968,7 @@ set_chars_option(win_T *wp, char_u **varp)
while (*s != NUL && *s != ',')
{
c1 = get_encoded_char_adv(&s);
if (mb_char2cells(c1) > 1)
if (char2cells(c1) > 1)
return e_invarg;
++multispace_len;
}
Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_display.vim
Expand Up @@ -266,6 +266,8 @@ func Test_eob_fillchars()
call assert_fails(':set fillchars=eob:xy', 'E474:')
call assert_fails(':set fillchars=eob:\255', 'E474:')
call assert_fails(':set fillchars=eob:<ff>', 'E474:')
call assert_fails(":set fillchars=eob:\x01", 'E474:')
call assert_fails(':set fillchars=eob:\\x01', 'E474:')
" default is ~
new
redraw
Expand Down
16 changes: 15 additions & 1 deletion src/testdir/test_listchars.vim
Expand Up @@ -333,14 +333,28 @@ func Test_listchars_invalid()
call assert_fails('set listchars=space:xx', 'E474:')
call assert_fails('set listchars=tab:xxxx', 'E474:')

" Has non-single width character
" Has double-width character
call assert_fails('set listchars=space:·', 'E474:')
call assert_fails('set listchars=tab:·x', 'E474:')
call assert_fails('set listchars=tab:x·', 'E474:')
call assert_fails('set listchars=tab:xx·', 'E474:')
call assert_fails('set listchars=multispace:·', 'E474:')
call assert_fails('set listchars=multispace:xxx·', 'E474:')

" Has control character
call assert_fails("set listchars=space:\x01", 'E474:')
call assert_fails("set listchars=tab:\x01x", 'E474:')
call assert_fails("set listchars=tab:x\x01", 'E474:')
call assert_fails("set listchars=tab:xx\x01", 'E474:')
call assert_fails("set listchars=multispace:\x01", 'E474:')
call assert_fails("set listchars=multispace:xxx\x01", 'E474:')
call assert_fails('set listchars=space:\\x01', 'E474:')
call assert_fails('set listchars=tab:\\x01x', 'E474:')
call assert_fails('set listchars=tab:x\\x01', 'E474:')
call assert_fails('set listchars=tab:xx\\x01', 'E474:')
call assert_fails('set listchars=multispace:\\x01', 'E474:')
call assert_fails('set listchars=multispace:xxx\\x01', 'E474:')

enew!
set ambiwidth& listchars& ff&
endfunction
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -749,6 +749,8 @@ static char *(features[]) =

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

0 comments on commit 60618c8

Please sign in to comment.