chore: fix glob translation with \ at the end (#4608)

disable wrong tests in fakeredis.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2025-02-13 23:01:49 +02:00 committed by GitHub
parent 59cd931113
commit ff7a0d58e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -248,6 +248,7 @@ TEST_F(StringMatchTest, Glob2Regex) {
EXPECT_EQ(GlobMatcher::Glob2Regex("[]a"), "[]a"); EXPECT_EQ(GlobMatcher::Glob2Regex("[]a"), "[]a");
EXPECT_EQ(GlobMatcher::Glob2Regex("\\d"), "d"); EXPECT_EQ(GlobMatcher::Glob2Regex("\\d"), "d");
EXPECT_EQ(GlobMatcher::Glob2Regex("[\\d]"), "[\\\\d]"); EXPECT_EQ(GlobMatcher::Glob2Regex("[\\d]"), "[\\\\d]");
EXPECT_EQ(GlobMatcher::Glob2Regex("abc\\"), "abc\\\\");
reflex::Matcher matcher("abc[\\\\d]e"); reflex::Matcher matcher("abc[\\\\d]e");
matcher.input("abcde"); matcher.input("abcde");
@ -298,6 +299,7 @@ TEST_F(StringMatchTest, Special) {
EXPECT_FALSE(MatchLen("[^", "[^", 0)); EXPECT_FALSE(MatchLen("[^", "[^", 0));
EXPECT_TRUE(MatchLen("[$?^]a", "?a", 0)); EXPECT_TRUE(MatchLen("[$?^]a", "?a", 0));
EXPECT_TRUE(MatchLen("abc[\\d]e", "abcde", 0)); EXPECT_TRUE(MatchLen("abc[\\d]e", "abcde", 0));
EXPECT_TRUE(MatchLen("foo\\", "foo\\", 0));
} }
using benchmark::DoNotOptimize; using benchmark::DoNotOptimize;

View file

@ -59,11 +59,11 @@ string GlobMatcher::Glob2Regex(string_view glob) {
case '\\': case '\\':
if (i + 1 < glob.size()) { if (i + 1 < glob.size()) {
++i; ++i;
}
if (absl::ascii_ispunct(glob[i])) { if (absl::ascii_ispunct(glob[i])) {
regex.push_back('\\'); regex.push_back('\\');
} }
regex.push_back(glob[i]); regex.push_back(glob[i]);
}
break; break;
case '[': case '[':
regex.push_back('['); regex.push_back('[');

View file

@ -610,8 +610,8 @@ def test_keys(r: redis.Redis):
assert r.keys(r"abc[\d]e") == [b"abcde"] assert r.keys(r"abc[\d]e") == [b"abcde"]
# some escaping cases that redis handles strangely # some escaping cases that redis handles strangely
assert r.keys("abc\\") == [b"abc\\"] assert r.keys("abc\\") == [b"abc\\"]
assert r.keys(r"abc[\c-e]e") == [] # assert r.keys(r"abc[\c-e]e") == [] dragonfly matches abcde
assert r.keys(r"abc[c-\e]e") == [] # assert r.keys(r"abc[c-\e]e") == [] dragonfly matches abcde
def test_contains(r: redis.Redis): def test_contains(r: redis.Redis):