Fix SLRE_IGNORE_CASE handling

This commit is contained in:
Sergey Lyubka 2015-06-10 11:19:43 +01:00
parent 0419690215
commit ace9f34999
2 changed files with 10 additions and 2 deletions

4
slre.c
View File

@ -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] != ']' && if (re[len] != '-' && re[len + 1] == '-' && re[len + 2] != ']' &&
re[len + 2] != '\0') { re[len + 2] != '\0') {
result = info->flags && SLRE_IGNORE_CASE ? 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; len += 3;
} else { } else {
result = match_op((unsigned char *) re + len, (unsigned char *) s, info); result = match_op((unsigned char *) re + len, (unsigned char *) s, info);

View File

@ -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);
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 */ /* Example: HTTP request */
const char *request = " GET /index.html HTTP/1.0\r\n\r\n"; const char *request = " GET /index.html HTTP/1.0\r\n\r\n";