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

Properly base32 decode 'iIoOlL' characters. #59

Merged
merged 8 commits into from
Oct 26, 2017
Merged
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
17 changes: 17 additions & 0 deletions tests/test_base32.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
from ulid import base32


@pytest.fixture(scope='session')
def decoding_alphabet():
"""
Fixture that yields the entire alphabet that is valid for base32 decoding.
"""
return base32.ENCODING + 'lLiIoO'


def test_encode_handles_ulid_and_returns_26_char_string(valid_bytes_128):
"""
Assert that :func:`~ulid.base32.encode` encodes a valid 128 bit bytes object into a :class:`~str`
Expand Down Expand Up @@ -235,3 +243,12 @@ def test_decode_randomness_raises_on_non_ascii_str(invalid_str_encoding):
"""
with pytest.raises(ValueError):
base32.decode_randomness(invalid_str_encoding)


def test_decode_table_has_value_for_entire_decoding_alphabet(decoding_alphabet):
"""
Assert that :attr:`~ulid.base32.DECODING` stores a valid value mapping for all characters that
can be base32 decoded.
"""
for char in decoding_alphabet:
assert base32.DECODING[ord(char)] != 0xFF, 'Character "{}" decoded improperly'.format(char)
21 changes: 21 additions & 0 deletions tests/test_bugs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
test_bugs
~~~~~~~~~

Tests for validating reported bugs have been fixed.
"""
from ulid import api


def test_github_issue_58():
"""
Assert that :func:`~ulid.api.from_str` can properly decode strings that
contain Base32 "translate" characters.

Base32 "translate" characters are: "iI, lL, oO".

Issue: https://github.com/ahawker/ulid/issues/58
"""
value = '01BX73KC0TNH409RTFD1JXKmO0'
instance = api.from_str(value)
assert instance.str == '01BX73KC0TNH409RTFD1JXKM00'
6 changes: 3 additions & 3 deletions ulid/base32.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0xFF, 0x12, 0x13, 0xFF, 0x14, 0x15, 0xFF,
0x0F, 0x10, 0x11, 0x01, 0x12, 0x13, 0x01, 0x14, 0x15, 0x00,
0x16, 0x17, 0x18, 0x19, 0x1A, 0xFF, 0x1B, 0x1C, 0x1D, 0x1E,
0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0xFF, 0x12, 0x13, 0xFF, 0x14,
0x15, 0xFF, 0x16, 0x17, 0x18, 0x19, 0x1A, 0xFF, 0x1B, 0x1C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x01, 0x12, 0x13, 0x01, 0x14,
0x15, 0x00, 0x16, 0x17, 0x18, 0x19, 0x1A, 0xFF, 0x1B, 0x1C,
0x1D, 0x1E, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
Expand Down