From ace9f349992f6789ec4d48c36fa42b509227b2e0 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 10 Jun 2015 11:19:43 +0100 Subject: [PATCH] Fix SLRE_IGNORE_CASE handling --- slre.c | 4 ++-- unit_test.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/slre.c b/slre.c index 9ac96a3..643dae1 100644 --- a/slre.c +++ b/slre.c @@ -167,8 +167,8 @@ static int match_set(const char *re, int re_len, const char *s, if (re[len] != '-' && re[len + 1] == '-' && re[len + 2] != ']' && re[len + 2] != '\0') { result = info->flags && SLRE_IGNORE_CASE ? - *s >= re[len] && *s <= re[len + 2] : - tolower(*s) >= tolower(re[len]) && tolower(*s) <= tolower(re[len + 2]); + tolower(*s) >= tolower(re[len]) && tolower(*s) <= tolower(re[len + 2]) : + *s >= re[len] && *s <= re[len + 2]; len += 3; } else { result = match_op((unsigned char *) re + len, (unsigned char *) s, info); diff --git a/unit_test.c b/unit_test.c index c12d59d..077aeb3 100644 --- a/unit_test.c +++ b/unit_test.c @@ -213,6 +213,14 @@ int main(void) { ASSERT(slre_match( "a+$" ,"Xaa", 3, NULL, 0, 0) == 3); ASSERT(slre_match( "a*$" ,"Xaa", 3, NULL, 0, 0) == 3); + /* Ignore case flag */ + ASSERT(slre_match("[a-h]+", "abcdefghxxx", 11, NULL, 0, 0) == 8); + ASSERT(slre_match("[A-H]+", "ABCDEFGHyyy", 11, NULL, 0, 0) == 8); + ASSERT(slre_match("[a-h]+", "ABCDEFGHyyy", 11, NULL, 0, 0) == SLRE_NO_MATCH); + ASSERT(slre_match("[A-H]+", "abcdefghyyy", 11, NULL, 0, 0) == SLRE_NO_MATCH); + ASSERT(slre_match("[a-h]+", "ABCDEFGHyyy", 11, NULL, 0, SLRE_IGNORE_CASE) == 8); + ASSERT(slre_match("[A-H]+", "abcdefghyyy", 11, NULL, 0, SLRE_IGNORE_CASE) == 8); + { /* Example: HTTP request */ const char *request = " GET /index.html HTTP/1.0\r\n\r\n";