Skip to content

Commit 7580849

Browse files
committed
patch 8.1.0043: ++bad argument of :edit does not work properly
Problem: ++bad argument of :edit does not work properly. Solution: Return FAIL from get_bad_opt() only when there is no valid argument. (Dominique Pelle, Christian Brabandt, closes #2966, closes #2947)
1 parent f98b845 commit 7580849

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/ex_docmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5318,7 +5318,9 @@ get_bad_opt(char_u *p, exarg_T *eap)
53185318
eap->bad_char = BAD_DROP;
53195319
else if (MB_BYTE2LEN(*p) == 1 && p[1] == NUL)
53205320
eap->bad_char = *p;
5321-
return FAIL;
5321+
else
5322+
return FAIL;
5323+
return OK;
53225324
}
53235325
#endif
53245326

src/testdir/test_plus_arg_edit.vim

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
" Tests for complicated + argument to :edit command
22
function Test_edit()
3-
call writefile(["foo|bar"], "Xfile1")
4-
call writefile(["foo/bar"], "Xfile2")
3+
call writefile(["foo|bar"], "Xfile1")
4+
call writefile(["foo/bar"], "Xfile2")
55
edit +1|s/|/PIPE/|w Xfile1| e Xfile2|1 | s/\//SLASH/|w
66
call assert_equal(["fooPIPEbar"], readfile("Xfile1"))
77
call assert_equal(["fooSLASHbar"], readfile("Xfile2"))
88
call delete('Xfile1')
99
call delete('Xfile2')
1010
endfunction
11+
12+
func Test_edit_bad()
13+
if !has('multi_byte')
14+
finish
15+
endif
16+
17+
" Test loading a utf8 file with bad utf8 sequences.
18+
call writefile(["[\xff][\xc0][\xe2\x89\xf0][\xc2\xc2]"], "Xfile")
19+
new
20+
21+
" Without ++bad=..., the default behavior is like ++bad=?
22+
e! ++enc=utf8 Xfile
23+
call assert_equal('[?][?][???][??]', getline(1))
24+
25+
e! ++enc=utf8 ++bad=_ Xfile
26+
call assert_equal('[_][_][___][__]', getline(1))
27+
28+
e! ++enc=utf8 ++bad=drop Xfile
29+
call assert_equal('[][][][]', getline(1))
30+
31+
e! ++enc=utf8 ++bad=keep Xfile
32+
call assert_equal("[\xff][\xc0][\xe2\x89\xf0][\xc2\xc2]", getline(1))
33+
34+
call assert_fails('e! ++enc=utf8 ++bad=foo Xfile', 'E474:')
35+
36+
bw!
37+
call delete('Xfile')
38+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
43,
764766
/**/
765767
42,
766768
/**/

0 commit comments

Comments
 (0)