Skip to content

Commit 628011c

Browse files
committed
Handle only stop parameter set, but not start.
If start is not specified, the value given for stop will be injected into start's position; it is wise to safeguard against this. (via @yaauie)
1 parent 49294de commit 628011c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/redis.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,16 @@ def bitop(operation, destkey, *keys)
909909
# Return the position of the first bit set to 1 or 0 in a string.
910910
#
911911
# @param [String] key
912-
# @param [Fixnum] bit wether to look for the first 1 or 0 bit
912+
# @param [Fixnum] bit whether to look for the first 1 or 0 bit
913913
# @param [Fixnum] start start index
914914
# @param [Fixnum] stop stop index
915915
# @return [Fixnum] the position of the first 1/0 bit.
916916
# -1 if looking for 1 and it is not found or start and stop are given.
917917
def bitpos(key, bit, start=nil, stop=nil)
918+
if stop and not start
919+
raise(ArgumentError, 'stop parameter specified without start parameter')
920+
end
921+
918922
synchronize do |client|
919923
command = [:bitpos, key, bit]
920924
command << start if start

test/bitpos_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,12 @@ def test_bitpos_one_intervals
5858
end
5959
end
6060

61+
def test_bitpos_raise_exception_if_stop_not_start
62+
target_version "2.9.11" do
63+
assert_raises(ArgumentError) do
64+
r.bitpos("foo", 0, nil, 2)
65+
end
66+
end
67+
end
68+
6169
end

0 commit comments

Comments
 (0)