patch 8.0.0623: error for invalid regexp is not very informative v8.0.0623
authorBram Moolenaar <Bram@vim.org>
Mon, 5 Jun 2017 14:54:08 +0000 (16:54 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 5 Jun 2017 14:54:08 +0000 (16:54 +0200)
Problem:    The message "Invalid range" is used for multiple errors.
Solution:   Add two more specific error messages. (Itchyny, Ken Hamada)

src/regexp.c
src/regexp_nfa.c
src/testdir/test_regexp_utf8.vim
src/version.c

index e1f6484c00a62f6696ba7d5295b0108101627570..de066a1015c8dfaf6096d3ca854ff711266e927d 100644 (file)
@@ -358,6 +358,8 @@ static char_u       *regprop(char_u *);
 static int re_mult_next(char *what);
 
 static char_u e_missingbracket[] = N_("E769: Missing ] after %s[");
+static char_u e_reverse_range[] = N_("E944: Reverse range in character class");
+static char_u e_large_class[] = N_("E945: Range too large in character class");
 static char_u e_unmatchedpp[] = N_("E53: Unmatched %s%%(");
 static char_u e_unmatchedp[] = N_("E54: Unmatched %s(");
 static char_u e_unmatchedpar[] = N_("E55: Unmatched %s)");
@@ -2426,14 +2428,14 @@ collection:
                                endc = coll_get_char();
 
                            if (startc > endc)
-                               EMSG_RET_NULL(_(e_invrange));
+                               EMSG_RET_NULL(_(e_reverse_range));
 #ifdef FEAT_MBYTE
                            if (has_mbyte && ((*mb_char2len)(startc) > 1
                                                 || (*mb_char2len)(endc) > 1))
                            {
-                               /* Limit to a range of 256 chars */
+                               /* Limit to a range of 256 chars. */
                                if (endc > startc + 256)
-                                   EMSG_RET_NULL(_(e_invrange));
+                                   EMSG_RET_NULL(_(e_large_class));
                                while (++startc <= endc)
                                    regmbc(startc);
                            }
index c490acb710af4778dc61291509c943cf29431aef..4e111f169fffa6c541154079d9e4a7958d57d741 100644 (file)
@@ -1853,7 +1853,7 @@ collection:
                        endc = startc;
                        startc = oldstartc;
                        if (startc > endc)
-                           EMSG_RET_FAIL(_(e_invrange));
+                           EMSG_RET_FAIL(_(e_reverse_range));
 
                        if (endc > startc + 2)
                        {
index c54b65081cc72654e1856018b3b0d7981fadf099..bec5e0ed4fadbfa59a7f7a11bf3bf5082216741a 100644 (file)
@@ -137,3 +137,20 @@ func Test_classes_re2()
   call s:classes_test()
   set re=0
 endfunc
+
+func Test_reversed_range()
+  for re in range(0, 2)
+    exe 'set re=' . re
+    call assert_fails('call match("abc def", "[c-a]")', 'E944:')
+  endfor
+  set re=0
+endfunc
+
+func Test_large_class()
+  set re=1
+  call assert_fails('call match("abc def", "[\u3000-\u4000]")', 'E945:')
+  set re=2
+  call assert_equal(0, 'abc def' =~# '[\u3000-\u4000]')
+  call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]')
+  set re=0
+endfunc
index 0304389b33d66633d3da98d0419b0d57a4401784..e07d2a8dc95146753b7f87dd2bd3a6d38b6ada3d 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    623,
 /**/
     622,
 /**/