One function

string_to_int in skorokithakis/shortuuid

The author described this change as fix: Fix string_to_int radix when alphabet_index is provided (#115). It counts as a record because the check below fails on the code as it stood at b8898871c and passes on 496cddf18, with nothing else changed between the two runs.

Fix saved2026-06-18
Sharing licenceBSD-3-Clause · COPYING
Change size+3 1

What the code was meant to do, written into the code itself as a docstring

Convert a string to a number, using the given alphabet. The input is assumed to have the most significant digit first. The alphabet_index, if provided, should map each character to its index: `{char: idx for idx, char in enumerate(alphabet)}`. This avoids rebuilding the index on each call when decoding multiple strings with the same alphabet. If this is passed, `alphabet` is ignored.

The change

1616 if alphabet_index is None:
1717 alphabet_index = {char: idx for idx, char in enumerate(alphabet)}
1818 number = 0
19- alpha_len = len(alphabet)
19+ # Derive the radix from the index so `alphabet` is truly ignored when
20+ # alphabet_index is passed, as documented above.
21+ alpha_len = len(alphabet_index)
2022 for char in string:
2123 try:
2224 number = number * alpha_len + alphabet_index[char]

The check that tells the two apart

failpass·shortuuid/test_shortuuid.py::DecodingEdgeCasesTest::test_string_to_int_ignores_alphabet_when_index_given

Check file shortuuid/test_shortuuid.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itb8898871c5b977549b4ecbecbb638d8e06d7359e
Broken version dated2025-12-01
Moduleshortuuid.main
Units changedstring_to_int
Fingerprintc44f3acf6ebcf1cc
Checked2026-08-17 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.