Skip to content

Commit df16079

Browse files
committed
fix(glob matching): Correctly match longer strings with '*' or '**' pattern
If string is longer than 16 chars we are using Reflex library for matching. When used pattern is '*' or '**' we are going to strip both of stars and have empty pattern. We should in this edge case inject manually star pattern. Fixes #4948 Signed-off-by: mkaruza <mario@dragonflydb.io>
1 parent a02af96 commit df16079

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/core/glob_matcher.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ GlobMatcher::GlobMatcher(string_view pattern, bool case_sensitive)
236236
regex.push_back('i');
237237
}
238238
regex.push_back(')');
239-
regex.append(Glob2Regex(pattern));
239+
if (pattern.empty()) {
240+
// Edge case, pattern is empty so it was '*' or '**'. Set regex manually.
241+
regex.append(Glob2Regex("*"sv));
242+
} else {
243+
regex.append(Glob2Regex(pattern));
244+
}
240245
matcher_.pattern(regex);
241246
#elif USE_PCRE2
242247
string regex("(?s"); // dotall mode

src/server/dragonfly_test.cc

+17
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ TEST_F(DflyEngineTest, PSubscribe) {
548548
EXPECT_EQ("a*", msg.pattern);
549549
}
550550

551+
TEST_F(DflyEngineTest, PSubscribeMatchOnlyStar) {
552+
single_response_ = false;
553+
auto resp = pp_->at(1)->Await([&] { return Run({"psubscribe", "*"}); });
554+
EXPECT_THAT(resp, ArrLen(3));
555+
resp = pp_->at(0)->Await([&] { return Run({"PUBLISH", "1234567890123456", "abc"}); });
556+
EXPECT_THAT(resp, IntArg(1));
557+
558+
pp_->AwaitFiberOnAll([](ProactorBase* pb) {});
559+
560+
ASSERT_EQ(1, SubscriberMessagesLen("IO1"));
561+
562+
const auto& msg = GetPublishedMessage("IO1", 0);
563+
EXPECT_EQ("abc", msg.message);
564+
EXPECT_EQ("1234567890123456", msg.channel);
565+
EXPECT_EQ("*", msg.pattern);
566+
}
567+
551568
TEST_F(DflyEngineTest, Unsubscribe) {
552569
auto resp = Run({"unsubscribe", "a"});
553570
EXPECT_THAT(resp.GetVec(), ElementsAre("unsubscribe", "a", IntArg(0)));

0 commit comments

Comments
 (0)