Skip to content

Commit 78ba933

Browse files
chrisbrabrammool
authored andcommitted
patch 8.2.3265: smartcase does not work correctly in very magic pattern
Problem: Smartcase does not work correctly in very magic pattern. Solution: Take the magicness into account when skipping over regexp items. (Christian Brabandt, closes #8682, closes #7845)
1 parent f24f51d commit 78ba933

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/search.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ ignorecase_opt(char_u *pat, int ic_in, int scs)
430430
pat_has_uppercase(char_u *pat)
431431
{
432432
char_u *p = pat;
433+
magic_T magic_val = MAGIC_ON;
434+
435+
// get the magicness of the pattern
436+
(void)skip_regexp_ex(pat, NUL, magic_isset(), NULL, NULL, &magic_val);
433437

434438
while (*p != NUL)
435439
{
@@ -441,7 +445,7 @@ pat_has_uppercase(char_u *pat)
441445
return TRUE;
442446
p += l;
443447
}
444-
else if (*p == '\\')
448+
else if (*p == '\\' && magic_val == MAGIC_ON)
445449
{
446450
if (p[1] == '_' && p[2] != NUL) // skip "\_X"
447451
p += 3;
@@ -452,6 +456,11 @@ pat_has_uppercase(char_u *pat)
452456
else
453457
p += 1;
454458
}
459+
else if ((*p == '%' || *p == '_') && magic_val == MAGIC_ALL)
460+
{
461+
if (p[1] != NUL) // skip "_X" and %X
462+
p += 2;
463+
}
455464
else if (MB_ISUPPER(*p))
456465
return TRUE;
457466
else

src/testdir/test_search.vim

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,4 +1912,58 @@ func Test_incsearch_substitute_dump2()
19121912
call delete('Xis_subst_script2')
19131913
endfunc
19141914

1915+
func Test_pattern_is_uppercase_smartcase()
1916+
new
1917+
let input=['abc', 'ABC', 'Abc', 'abC']
1918+
call setline(1, input)
1919+
call cursor(1,1)
1920+
" default, matches firstline
1921+
%s/abc//g
1922+
call assert_equal(['', 'ABC', 'Abc', 'abC'],
1923+
\ getline(1, '$'))
1924+
1925+
set smartcase ignorecase
1926+
sil %d
1927+
call setline(1, input)
1928+
call cursor(1,1)
1929+
" with smartcase and incsearch set, matches everything
1930+
%s/abc//g
1931+
call assert_equal(['', '', '', ''], getline(1, '$'))
1932+
1933+
sil %d
1934+
call setline(1, input)
1935+
call cursor(1,1)
1936+
" with smartcase and incsearch set and found an uppercase letter,
1937+
" match only that.
1938+
%s/abC//g
1939+
call assert_equal(['abc', 'ABC', 'Abc', ''],
1940+
\ getline(1, '$'))
1941+
1942+
sil %d
1943+
call setline(1, input)
1944+
call cursor(1,1)
1945+
exe "norm! vG$\<esc>"
1946+
" \%V should not be detected as uppercase letter
1947+
%s/\%Vabc//g
1948+
call assert_equal(['', '', '', ''], getline(1, '$'))
1949+
1950+
call setline(1, input)
1951+
call cursor(1,1)
1952+
exe "norm! vG$\<esc>"
1953+
" \v%V should not be detected as uppercase letter
1954+
%s/\v%Vabc//g
1955+
call assert_equal(['', '', '', ''], getline(1, '$'))
1956+
1957+
call setline(1, input)
1958+
call cursor(1,1)
1959+
exe "norm! vG$\<esc>"
1960+
" \v%VabC should be detected as uppercase letter
1961+
%s/\v%VabC//g
1962+
call assert_equal(['abc', 'ABC', 'Abc', ''],
1963+
\ getline(1, '$'))
1964+
1965+
set smartcase& ignorecase&
1966+
bw!
1967+
endfunc
1968+
19151969
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3265,
758760
/**/
759761
3264,
760762
/**/

0 commit comments

Comments
 (0)