Accept upper-case base32 in the pure-Python decoder - #51
Open
gaoflow wants to merge 1 commit into
Open
Conversation
The _geohash extension's build_base32_decode_map accepts upper-case base32 letters, but the pure-Python fallback's _base32_map is lower-case only, so decode/decode_exactly/bbox/neighbors/expand raise a bare KeyError on an upper-case geohash whenever the extension is not built. Populate _base32_map with the upper-case keys as well, and raise ValueError with the same message the extension reports for a character outside the alphabet instead of leaking KeyError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The library ships the same public API twice: the
_geohashRust/PyO3 extension and the pure-Pythongeohash.pyfallback used when the extension is not importable. The extension'sbuild_base32_decode_map(src/geohash_core.rs) deliberately accepts upper-case base32 letters, but the fallback's_base32_mapis lower-case only, so the decode path behaves differently depending on whether the compiled extension is present:Every entry point that decodes a code --
decode,decode_exactly,bbox,neighbors,expand-- goes through_decode_c2i, so all five raise a bareKeyErroron an upper-case geohash in the fallback while the extension returns a result. This is a widely hit path: PyPI ships a singlex86_64Linux wheel plus the sdist, and the README documents copyinggeohash.pystandalone, so macOS / Windows / aarch64 / musllinux installs and the standalone-copy use all run the fallback.This populates
_base32_mapwith the upper-case keys as well, mirroring the extension's map exactly -- only the base32 letters get an upper-case form, soa i l oandA I L Ostay invalid and mixed case works per character. It also replaces the bareKeyErrorfor an out-of-alphabet character with the sameValueError("geohash code is [0123456789bcdefghjkmnpqrstuvwxyz]+")the extension raises throughmap_error(src/lib.rs).Tests add upper-case, mixed-case and invalid-character cases across all five decode entry points. I also cross-checked the fallback against the built extension over 12k lower/upper/mixed geohashes and 3k invalid inputs; value and error type now match on every case, and the existing tests still pass.