From 5a284a436b9a26cee333eb88670e5a59670110de Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:27:56 -0700 Subject: [PATCH 1/8] Fix decoding lookup for 'o'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index 83f8a8a..e94dbe1 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -35,7 +35,7 @@ 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, + 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, From 9a5f9150b6e518c3f7b4eb1a68849d33f953f68d Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:30:57 -0700 Subject: [PATCH 2/8] Fix decoding lookup for 'O'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index e94dbe1..c2d9492 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -31,7 +31,7 @@ 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, 0xFF, 0x12, 0x13, 0xFF, 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, From 0086f9ed5c4b1b0ec80b5381817f70aaf42975f0 Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:34:36 -0700 Subject: [PATCH 3/8] Fix decoding lookup for 'I'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index c2d9492..ccda42a 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -31,7 +31,7 @@ 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, 0x00, + 0x0F, 0x10, 0x11, 0x01, 0x12, 0x13, 0xFF, 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, From 673e6a7f4bd0a31b6aa6a3c6c3c69760065855b9 Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:36:21 -0700 Subject: [PATCH 4/8] Fix decoding lookup for 'i'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index ccda42a..fc32498 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -34,7 +34,7 @@ 0x0F, 0x10, 0x11, 0x01, 0x12, 0x13, 0xFF, 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, + 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x01, 0x12, 0x13, 0xFF, 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, From 7464937923d24fc5b605fef9bda62284654576cc Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:43:45 -0700 Subject: [PATCH 5/8] Fix decoding lookup for 'L'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index fc32498..cbe1318 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -31,7 +31,7 @@ 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, 0x01, 0x12, 0x13, 0xFF, 0x14, 0x15, 0x00, + 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, 0x01, 0x12, 0x13, 0xFF, 0x14, From 5e38c15a7d155cbf70ce6dc768255e6ef586aba6 Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:45:32 -0700 Subject: [PATCH 6/8] Fix decoding lookup for 'l'. --- ulid/base32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ulid/base32.py b/ulid/base32.py index cbe1318..f7377b6 100644 --- a/ulid/base32.py +++ b/ulid/base32.py @@ -34,7 +34,7 @@ 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, 0x01, 0x12, 0x13, 0xFF, 0x14, + 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, From 269218cb23f19186fd9875753d48218f0a22ad7e Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:46:44 -0700 Subject: [PATCH 7/8] Add test for asserting all valid B32 decode characters have values. --- tests/test_base32.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_base32.py b/tests/test_base32.py index ab2df67..cac8214 100644 --- a/tests/test_base32.py +++ b/tests/test_base32.py @@ -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` @@ -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) From 886dcdd622e196280adc1266094357ccdd60044d Mon Sep 17 00:00:00 2001 From: Andrew Hawker Date: Wed, 25 Oct 2017 19:53:55 -0700 Subject: [PATCH 8/8] Add 'test_bugs' module. This module will be used to contain tests for asserting user reported bugs/issues have been fixed using exact inputs found in the bug reports. --- tests/test_bugs.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_bugs.py diff --git a/tests/test_bugs.py b/tests/test_bugs.py new file mode 100644 index 0000000..6ab8fcb --- /dev/null +++ b/tests/test_bugs.py @@ -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'