Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: wrong match with 'ic' and comparing multi-byte with single byte char #14756

Closed
wants to merge 2 commits into from

Commits on Jul 28, 2024

  1. regexp: wrong match with 'ic' and comparing multi-byte with single by…

    …te char
    
    This is v2 of v9.1.296, but still draft to see if this still breaks.
    
    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' 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
    
    There is one tricky thing for the backtracing engine. We also need to calculate
    correctly the number of bytes to compare the 2 different utf-8 strings s1 and
    s2. So we will count the number of characters in s1 that the byte len
    specified. Then we count the number of bytes to step over the same number of
    characters in string s2 and then we can correctly compare the 2 utf-8 strings.
    
    A similar 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.
    
    Note: this breaks Mail and CSS Syntax highlighting and CI on FreeBSD/MacOS
    vim#14487 and
    https://groups.google.com/d/msgid/vim_dev/CAJkCKXtui%3DDTWx9eV8Dbs19XoFL9b63ObSNXWCRvLsEZCB6yfw%40mail.gmail.com.
    
    fixes: vim#14294
    
    Signed-off-by: Christian Brabandt <cb@256bit.org>
    chrisbra committed Jul 28, 2024
    Configuration menu
    Copy the full SHA
    ac6ab88 View commit details
    Browse the repository at this point in the history
  2. compare characters in brace expressions using proper case folding

    Signed-off-by: Christian Brabandt <cb@256bit.org>
    chrisbra committed Jul 28, 2024
    Configuration menu
    Copy the full SHA
    bbc735a View commit details
    Browse the repository at this point in the history