diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-10 07:08:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 07:08:49 +0800 |
commit | f49408454ddb48016d51b48bcd9d5dab538f5cc7 (patch) | |
tree | 815676873f69c142fd4492ff4482bf1ab80c13b9 /runtime | |
parent | 7142c5dde939f6675cba4f02f616d94c1174cde2 (diff) | |
download | rneovim-f49408454ddb48016d51b48bcd9d5dab538f5cc7.tar.gz rneovim-f49408454ddb48016d51b48bcd9d5dab538f5cc7.tar.bz2 rneovim-f49408454ddb48016d51b48bcd9d5dab538f5cc7.zip |
vim-patch:9.1.0296: regexp: engines do not handle case-folding well (#28259)
Problem: Regex engines do not handle case-folding well
Solution: Correctly calculate byte length of characters to skip
When the regexp engine compares two utf-8 codepoints case insensitively
it may match an adjacent character, because it assumes it can step over
as many bytes as the pattern contains.
This however is not necessarily true because of case-folding, a
multi-byte UTF-8 character can be considered equal to some single-byte
value.
Let's consider the pattern 'ſ' and the string 's'. When comparing and
ignoring case, the single character 's' matches, and since it matches
Vim will try to step over the match (by the amount of bytes of the
pattern), assuming that since it matches, the length of both strings is
the same.
However in that case, it should only step over the single byte
value 's' so by 1 byte and try to start matching after it again. So for the
backtracking engine we need to ensure:
- we try to match the correct length for the pattern and the text
- in case of a match, we step over it correctly
The same thing can happen for the NFA engine, when skipping to the next
character to test for a match. We are skipping over the regstart
pointer, however we do not consider the case that because of
case-folding we may need to adjust the number of bytes to skip over. So
this needs to be adjusted in find_match_text() as well.
A related issue turned out, when prog->match_text is actually empty. In
that case we should try to find the next match and skip this condition.
fixes: vim/vim#14294
closes: vim/vim#14433
https://github.com/vim/vim/commit/7a27c108e0509f3255ebdcb6558e896c223e4d23
Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/dev_vimpatch.txt | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/runtime/doc/dev_vimpatch.txt b/runtime/doc/dev_vimpatch.txt index 1f48324d46..5cc7a70ba2 100644 --- a/runtime/doc/dev_vimpatch.txt +++ b/runtime/doc/dev_vimpatch.txt @@ -204,6 +204,7 @@ information. mb_ptr2char utf_ptr2char mb_head_off utf_head_off mb_tail_off utf_cp_bounds + mb_strnicmp2 utf_strnicmp mb_lefthalve grid_lefthalve mb_fix_col grid_fix_col utf_off2cells grid_off2cells |