Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix prefix_range_end #1647

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions etcd3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def prefix_range_end(prefix):
for i in reversed(range(len(s))):
if s[i] < 0xff:
s[i] = s[i] + 1
break
return bytes(s)
return s[:i + 1]
return b'\0'


def to_bytes(maybe_bytestring):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_etcd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,10 @@ def test_disarm_alarm(self, etcd):
class TestUtils(object):
def test_prefix_range_end(self):
assert etcd3.utils.prefix_range_end(b'foo') == b'fop'
assert etcd3.utils.prefix_range_end(b'ab\xff') == b'ac\xff'
assert etcd3.utils.prefix_range_end(b'ab\xff') == b'ac'
assert (etcd3.utils.prefix_range_end(b'a\xff\xff\xff\xff\xff')
== b'b\xff\xff\xff\xff\xff')
== b'b')
assert b'\0' == etcd3.utils.prefix_range_end(b'\xff\xff\xff\xff\xff')

def test_to_bytes(self):
assert isinstance(etcd3.utils.to_bytes(b'doot'), bytes) is True
Expand Down