Skip to content

Commit

Permalink
Merge 278c4da into 09747cb
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsk committed May 13, 2020
2 parents 09747cb + 278c4da commit 00482b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mock_redis/database.rb
Expand Up @@ -323,7 +323,7 @@ def redis_pattern_to_ruby_regex(pattern)
Regexp.new(
"^#{pattern}$".
gsub(/([+|()])/, '\\\\\1').
gsub(/([^\\])\?/, '\\1.').
gsub(/(?<!\\)\?/, '\\1.').
gsub(/([^\\])\*/, '\\1.*')
)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/commands/keys_spec.rb
Expand Up @@ -29,6 +29,7 @@

@redises.set('mock-redis-test:special-key?', 'true')
@redises.set('mock-redis-test:special-key*', 'true')
@redises.set('mock-redis-test:special-key-!?*', 'true')
end

describe 'the ? character' do
Expand All @@ -53,6 +54,22 @@
'mock-redis-test:special-key?',
]
end

context 'multiple ? characters' do
it "properly handles multiple consequtive '?' characters" do
@redises.keys('mock-redis-test:special-key-???').sort.should == [
'mock-redis-test:special-key-!?*',
]
end

context '\\? as a literal ' do
it 'handles multiple ? as both literal and special character' do
@redises.keys('mock-redis-test:special-key-?\??').sort.should == [
'mock-redis-test:special-key-!?*',
]
end
end
end
end

describe 'the * character' do
Expand Down

0 comments on commit 00482b1

Please sign in to comment.