mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
regexp_nfa: Fix invalid fallthrough in character class detection
When the end character in a range matches a different standard range (e.g., [0-z]), the range would be incorrectly detected as the class of the end character (CLASS_az). Instead of using a fallthrough, immediately FAIL when the end character doesn't match the expected range.
This commit is contained in:
@@ -634,6 +634,7 @@ static int nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl)
|
||||
config |= CLASS_o7;
|
||||
break;
|
||||
}
|
||||
return FAIL;
|
||||
case 'a':
|
||||
if (*(p + 2) == 'z') {
|
||||
config |= CLASS_az;
|
||||
@@ -642,6 +643,7 @@ static int nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl)
|
||||
config |= CLASS_af;
|
||||
break;
|
||||
}
|
||||
return FAIL;
|
||||
case 'A':
|
||||
if (*(p + 2) == 'Z') {
|
||||
config |= CLASS_AZ;
|
||||
@@ -650,7 +652,7 @@ static int nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl)
|
||||
config |= CLASS_AF;
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
return FAIL;
|
||||
default:
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -275,4 +275,16 @@ describe('character classes in regexp', function()
|
||||
diff(sixlines(string.sub(punct1, 1)..digits..punct2..upper..punct3..
|
||||
lower..punct4..ctrl2..iso_text))
|
||||
end)
|
||||
it('does not convert character class ranges to an incorrect class', function()
|
||||
source([[
|
||||
1 s/\%#=0[0-z]//g
|
||||
2 s/\%#=1[0-z]//g
|
||||
3 s/\%#=2[0-z]//g
|
||||
4 s/\%#=0[^0-z]//g
|
||||
5 s/\%#=1[^0-z]//g
|
||||
6 s/\%#=2[^0-z]//g
|
||||
]])
|
||||
diff(string.rep(ctrl1..punct1..punct4..ctrl2..iso_text..'\n', 3)
|
||||
..string.rep(digits..punct2..upper..punct3..lower..'\n', 3))
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user