From d4561d9ad19d348a7c9ea448e3e7be986ab353d1 Mon Sep 17 00:00:00 2001 From: lexborisov Date: Tue, 14 Mar 2017 00:08:57 +0300 Subject: [PATCH] Fixes for https://github.com/lexborisov/Modest/issues/15 --- source/modest/finder/match.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/source/modest/finder/match.c b/source/modest/finder/match.c index 97d5f9d..1043ef0 100644 --- a/source/modest/finder/match.c +++ b/source/modest/finder/match.c @@ -82,43 +82,34 @@ bool modest_finder_match_attribute_ws(myhtml_token_attr_t* attr, const char* key if(myhtml_strncasecmp(key, attr->key.data, key_len) == 0) { size_t i = 0; + size_t begin; if(attr->value.length >= value_len) { if(case_sensitive) { while(i < attr->value.length) { - size_t end = i + value_len; + begin = i; + while(i < attr->value.length && myhtml_utils_whithspace(attr->value.data[i], !=, &&)) {i++;} - if(end > attr->value.length) - return false; - - if( - (myhtml_strncmp(value, &attr->value.data[i], value_len) == 0) && - (myhtml_utils_whithspace(attr->value.data[end], ==, ||) || end == attr->value.length)) - { + if((i - begin) == value_len && (myhtml_strncmp(value, &attr->value.data[begin], value_len) == 0)) { return true; } - - i++; + /* skip all ws */ + while(i < attr->value.length && myhtml_utils_whithspace(attr->value.data[i], ==, ||)) {i++;} } } else { while(i < attr->value.length) { - size_t end = i + value_len; + begin = i; + while(i < attr->value.length && myhtml_utils_whithspace(attr->value.data[i], !=, &&)) {i++;} - if(end > attr->value.length) - return false; - - if( - (myhtml_strncasecmp(value, &attr->value.data[i], value_len) == 0) && - (myhtml_utils_whithspace(attr->value.data[end], ==, ||) || end == attr->value.length)) - { + if((i - begin) == value_len && (myhtml_strncasecmp(value, &attr->value.data[begin], value_len) == 0)) { return true; } - - i++; + /* skip all ws */ + while(i < attr->value.length && myhtml_utils_whithspace(attr->value.data[i], ==, ||)) {i++;} } } }