Skip to content

Commit

Permalink
Prevent converting numbers with leading zeroes to int. (#390) (#405)
Browse files Browse the repository at this point in the history
* Prevent converting numbers with leading zeroes to int.
* But do treat a single 0 as an int.
  • Loading branch information
jap authored Jul 1, 2020
1 parent a2fecef commit c723a16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion imapclient/response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def atom(src, token):
return literal_text
elif len(token) >= 2 and (token[:1] == token[-1:] == b'"'):
return token[1:-1]
elif token.isdigit():
elif token.isdigit() and (token[:1] != b'0' or len(token) == 1):
# this prevents converting items like 0123 to 123
return int(token)
else:
return token
Expand Down
6 changes: 6 additions & 0 deletions tests/test_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def test_string(self):
def test_int(self):
self._test(b'45', 45)

def test_int_zero(self):
self._test(b'0', 0)

def test_not_an_int(self):
self._test(b'0123', b'0123')

def test_nil(self):
self._test(b'NIL', None)

Expand Down

0 comments on commit c723a16

Please sign in to comment.