Skip to content

Commit

Permalink
gh-674: Fix broken substring match.
Browse files Browse the repository at this point in the history
It also replaces celix_utils_stringEquals with cheaper celix_utils_isStringNullOrEmpty.
  • Loading branch information
PengZheng committed Apr 1, 2024
1 parent eb2cf8a commit 4d94de2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions libs/utils/gtest/src/FilterTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ TEST_F(FilterTestSuite, SubStringWithArrayAttributesTest) {
celix_autoptr(celix_filter_t) filter3 = celix_filter_create("(strings=*Johnson)");
EXPECT_TRUE(filter3 != nullptr);
EXPECT_FALSE(celix_filter_match(filter3, props));

celix_autoptr(celix_filter_t) filter4 = celix_filter_create("(strings=Jane*)");
EXPECT_TRUE(filter4 != nullptr);
EXPECT_TRUE(celix_filter_match(filter4, props));

celix_autoptr(celix_filter_t) filter5 = celix_filter_create("(strings=*Smith)");
EXPECT_TRUE(filter5 != nullptr);
EXPECT_TRUE(celix_filter_match(filter5, props));
}

#include "filter.h"
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ static bool celix_filter_matchSubStringForValue(const celix_filter_t* filter, co

const char* currentValue = value;

if (initial) {
if (!celix_utils_isStringNullOrEmpty(initial)) {
const char* found = strstr(value, initial);
currentValue = found + celix_utils_strlen(initial);
if (!found || found != value) {
Expand All @@ -702,7 +702,7 @@ static bool celix_filter_matchSubStringForValue(const celix_filter_t* filter, co
currentValue = found + celix_utils_strlen(substr);
}

if (!celix_utils_stringEquals(final, "")) {
if (!celix_utils_isStringNullOrEmpty(final)) {
const char* found = strstr(currentValue, final);
if (!found || found + celix_utils_strlen(final) != value + strLen) {
return false;
Expand All @@ -719,8 +719,8 @@ static bool celix_filter_matchSubString(const celix_filter_t* filter, const celi
if (celix_filter_matchSubStringForValue(filter, substr)) {
return true;
}
return false;
}
return false;
}
return celix_filter_matchSubStringForValue(filter, entry->value);
}
Expand Down

0 comments on commit 4d94de2

Please sign in to comment.