[EGIT] [e16/e16] master 01/01: Regular expression matching fixes

kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=44b31fbbd123546ede1ff2524b23f6b642014e2c

commit 44b31fbbd123546ede1ff2524b23f6b642014e2c
Author: Kim Woelders <k...@woelders.dk>
Date:   Fri Nov 12 17:02:48 2021 +0100

    Regular expression matching fixes
    
    Patch by Dennis Nezic <denn...@dennisn.mooo.com>:
    
    Currently, in matches.cfg, "Title *bla ..." will match any title with
    "bla" in it ... but it should only match if the title ends in bla,
    right?
---
 src/regex.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/regex.c b/src/regex.c
index 97cc9489..3504f8dd 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -102,9 +102,26 @@ matchregexp(const char *rx, const char *s)
             i = isafter(i, s, rx2);
             if (i < 0)
                return 0;
+            // Because the for loop will increment i (the index
+            // into string s) at the end of this block, but i now
+            // already points to the next char in s, this next char
+            // gets ignored.
+            // Without this next decrement, if the regex is *bla,
+            // it will incorrectly say that blax matches, although
+            // correctly say that blaxy doesn't. Ie. char x is skipped
+            if (i > 0)
+               i--;
          }
        else
-          return match;
+         {
+            // We arrived at the end of the regex BUT if it doesn't
+            // end with the wildcard * and there are more chars
+            // in s remaining to be matched, we should return 0
+            if ((i < len) && (rx[l - 1] != '*'))
+               return 0;
+            else
+               return match;
+         }
      }
    return match;
 }

-- 


Read more here: Source link