vim-patch:8.2.4693: new regexp does not accept pattern "\%>0v"

Problem:    new regexp does not accept pattern "\%>0v".
Solution:   Do accept digit zero.

72bb10df1f

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2022-11-05 15:56:15 +08:00
parent 78e69412ac
commit 77e25e56d8
3 changed files with 20 additions and 3 deletions

View File

@@ -2091,6 +2091,7 @@ static char_u *regatom(int *flagp)
uint32_t n = 0; uint32_t n = 0;
int cmp; int cmp;
bool cur = false; bool cur = false;
bool got_digit = false;
cmp = c; cmp = c;
if (cmp == '<' || cmp == '>') { if (cmp == '<' || cmp == '>') {
@@ -2101,6 +2102,7 @@ static char_u *regatom(int *flagp)
c = getchr(); c = getchr();
} }
while (ascii_isdigit(c)) { while (ascii_isdigit(c)) {
got_digit = true;
n = n * 10 + (uint32_t)(c - '0'); n = n * 10 + (uint32_t)(c - '0');
c = getchr(); c = getchr();
} }
@@ -2115,7 +2117,7 @@ static char_u *regatom(int *flagp)
*regcode++ = (char_u)cmp; *regcode++ = (char_u)cmp;
} }
break; break;
} else if (c == 'l' || c == 'c' || c == 'v') { } else if ((c == 'l' || c == 'c' || c == 'v') && (cur || got_digit)) {
if (cur && n) { if (cur && n) {
semsg(_(e_regexp_number_after_dot_pos_search_chr), no_Magic(c)); semsg(_(e_regexp_number_after_dot_pos_search_chr), no_Magic(c));
rc_did_emsg = true; rc_did_emsg = true;

View File

@@ -2141,6 +2141,7 @@ static int nfa_regatom(void)
int64_t n = 0; int64_t n = 0;
const int cmp = c; const int cmp = c;
bool cur = false; bool cur = false;
bool got_digit = false;
if (c == '<' || c == '>') { if (c == '<' || c == '>') {
c = getchr(); c = getchr();
@@ -2161,11 +2162,12 @@ static int nfa_regatom(void)
} }
n = n * 10 + (c - '0'); n = n * 10 + (c - '0');
c = getchr(); c = getchr();
got_digit = true;
} }
if (c == 'l' || c == 'c' || c == 'v') { if (c == 'l' || c == 'c' || c == 'v') {
int32_t limit = INT32_MAX; int32_t limit = INT32_MAX;
if (!cur && n == 0) { if (!cur && !got_digit) {
semsg(_(e_nfa_regexp_missing_value_in_chr), no_Magic(c)); semsg(_(e_nfa_regexp_missing_value_in_chr), no_Magic(c));
return FAIL; return FAIL;
} }

View File

@@ -105,16 +105,29 @@ func Test_multi_failure()
set re=0 set re=0
endfunc endfunc
func Test_column_failure() func Test_column_success_failure()
new
call setline(1, 'xbar')
set re=1 set re=1
%s/\%>0v./A/
call assert_equal('Abar', getline(1))
call assert_fails('/\%v', 'E71:') call assert_fails('/\%v', 'E71:')
call assert_fails('/\%>v', 'E71:')
call assert_fails('/\%c', 'E71:') call assert_fails('/\%c', 'E71:')
call assert_fails('/\%<c', 'E71:')
call assert_fails('/\%l', 'E71:') call assert_fails('/\%l', 'E71:')
set re=2 set re=2
%s/\%>0v./B/
call assert_equal('Bbar', getline(1))
call assert_fails('/\%v', 'E1273:') call assert_fails('/\%v', 'E1273:')
call assert_fails('/\%>v', 'E1273:')
call assert_fails('/\%c', 'E1273:') call assert_fails('/\%c', 'E1273:')
call assert_fails('/\%<c', 'E1273:')
call assert_fails('/\%l', 'E1273:') call assert_fails('/\%l', 'E1273:')
set re=0 set re=0
bwipe!
endfunc endfunc
func Test_recursive_addstate() func Test_recursive_addstate()