vim-patch:9.1.0217: regexp: verymagic cannot match before/after a mark (#28074)

Problem:  regexp: verymagic cannot match before/after a mark
Solution: Correctly check for the very magic check (Julio B)

Fix regexp parser for \v%>'m and \v%<'m
Currently \v%'m works fine, but it is unable to match before or after
the position of mark m.

closes: vim/vim#14309

46fa3c7e27

Co-authored-by: Julio B <julio.bacel@gmail.com>
This commit is contained in:
zeertzjq 2024-03-28 18:15:41 +08:00 committed by GitHub
parent c804d7968b
commit 6364fc617d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -4494,7 +4494,7 @@ static uint8_t *regatom(int *flagp)
n = n * 10 + (uint32_t)(c - '0'); n = n * 10 + (uint32_t)(c - '0');
c = getchr(); c = getchr();
} }
if (c == '\'' && n == 0) { if (no_Magic(c) == '\'' && n == 0) {
// "\%'m", "\%<'m" and "\%>'m": Mark // "\%'m", "\%<'m" and "\%>'m": Mark
c = getchr(); c = getchr();
ret = regnode(RE_MARK); ret = regnode(RE_MARK);
@ -10218,7 +10218,7 @@ static int nfa_regatom(void)
} }
EMIT((int)n); EMIT((int)n);
break; break;
} else if (c == '\'' && n == 0) { } else if (no_Magic(c) == '\'' && n == 0) {
// \%'m \%<'m \%>'m // \%'m \%<'m \%>'m
EMIT(cmp == '<' ? NFA_MARK_LT EMIT(cmp == '<' ? NFA_MARK_LT
: cmp == '>' ? NFA_MARK_GT : NFA_MARK); : cmp == '>' ? NFA_MARK_GT : NFA_MARK);

View File

@ -842,12 +842,26 @@ func Regex_Mark()
%d %d
endfunc endfunc
" Same test as abobe, but use verymagic
func Regex_Mark_Verymagic()
call append(0, ['', '', '', 'Marks:', 'asdfSasdfsadfEasdf', 'asdfSas',
\ 'dfsadfEasdf', '', '', '', '', ''])
call cursor(4, 1)
exe "normal jfSmsfEme:.-4,.+6s/\\v.%>'s.*%<'e../here/\<CR>"
exe "normal jfSmsj0fEme:.-4,.+6s/\\v.%>'s\\_.*%<'e../again/\<CR>"
call assert_equal(['', '', '', 'Marks:', 'asdfhereasdf', 'asdfagainasdf',
\ '', '', '', '', '', ''], getline(1, '$'))
%d
endfunc
func Test_matching_marks() func Test_matching_marks()
new new
set regexpengine=1 set regexpengine=1
call Regex_Mark() call Regex_Mark()
call Regex_Mark_Verymagic()
set regexpengine=2 set regexpengine=2
call Regex_Mark() call Regex_Mark()
call Regex_Mark_Verymagic()
bwipe! bwipe!
endfunc endfunc