]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.1.0296: regexp: engines do not handle case-folding well v9.1.0296
authorChristian Brabandt <cb@256bit.org>
Tue, 9 Apr 2024 20:53:19 +0000 (22:53 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 9 Apr 2024 20:53:19 +0000 (22:53 +0200)
commit7a27c108e0509f3255ebdcb6558e896c223e4d23
tree9c900010ad085e5b29d18af5a4ca3658f672c710
parentd2b95b8446233e0021a8c0cd672f8fae748e3955
patch 9.1.0296: regexp: engines do not handle case-folding well

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: #14294
closes: #14433

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/mbyte.c
src/proto/mbyte.pro
src/regexp.c
src/regexp_bt.c
src/regexp_nfa.c
src/testdir/test_regexp_utf8.vim
src/version.c
src/vim.h