Skip to content

Commit 966e58e

Browse files
committed
patch 8.0.0623: error for invalid regexp is not very informative
Problem: The message "Invalid range" is used for multiple errors. Solution: Add two more specific error messages. (Itchyny, Ken Hamada)
1 parent c5e2b04 commit 966e58e

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/regexp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ static char_u *regprop(char_u *);
358358
static int re_mult_next(char *what);
359359

360360
static char_u e_missingbracket[] = N_("E769: Missing ] after %s[");
361+
static char_u e_reverse_range[] = N_("E944: Reverse range in character class");
362+
static char_u e_large_class[] = N_("E945: Range too large in character class");
361363
static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%(");
362364
static char_u e_unmatchedp[] = N_("E54: Unmatched %s(");
363365
static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
@@ -2426,14 +2428,14 @@ regatom(int *flagp)
24262428
endc = coll_get_char();
24272429

24282430
if (startc > endc)
2429-
EMSG_RET_NULL(_(e_invrange));
2431+
EMSG_RET_NULL(_(e_reverse_range));
24302432
#ifdef FEAT_MBYTE
24312433
if (has_mbyte && ((*mb_char2len)(startc) > 1
24322434
|| (*mb_char2len)(endc) > 1))
24332435
{
2434-
/* Limit to a range of 256 chars */
2436+
/* Limit to a range of 256 chars. */
24352437
if (endc > startc + 256)
2436-
EMSG_RET_NULL(_(e_invrange));
2438+
EMSG_RET_NULL(_(e_large_class));
24372439
while (++startc <= endc)
24382440
regmbc(startc);
24392441
}

src/regexp_nfa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ nfa_regatom(void)
18531853
endc = startc;
18541854
startc = oldstartc;
18551855
if (startc > endc)
1856-
EMSG_RET_FAIL(_(e_invrange));
1856+
EMSG_RET_FAIL(_(e_reverse_range));
18571857

18581858
if (endc > startc + 2)
18591859
{

src/testdir/test_regexp_utf8.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,20 @@ func Test_classes_re2()
137137
call s:classes_test()
138138
set re=0
139139
endfunc
140+
141+
func Test_reversed_range()
142+
for re in range(0, 2)
143+
exe 'set re=' . re
144+
call assert_fails('call match("abc def", "[c-a]")', 'E944:')
145+
endfor
146+
set re=0
147+
endfunc
148+
149+
func Test_large_class()
150+
set re=1
151+
call assert_fails('call match("abc def", "[\u3000-\u4000]")', 'E945:')
152+
set re=2
153+
call assert_equal(0, 'abc def' =~# '[\u3000-\u4000]')
154+
call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]')
155+
set re=0
156+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
623,
767769
/**/
768770
622,
769771
/**/

0 commit comments

Comments
 (0)