Repository navigation
Reject non-ASCII case equivalents in country and currency codes - #551
Open
Enesuygurs wants to merge 1 commit into
Open
Enesuygurs wants to merge 1 commit into
Enesuygurs wants to merge 1 commit into
Conversation
With ignore_case=True, country_code() and currency() compared value.upper() against the ISO lists. str.upper() maps letters such as dotless i (U+0131), long s (U+017F) and the fi ligature (U+FB01) onto ASCII, so "ıt", "ıta", "fiN" and "uſd" were accepted as IT, ITA, FIN and USD. Require ASCII input before case-insensitive matching.
This branch has not been deployed
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.
With
ignore_case=True,country_code()andcurrency()comparevalue.upper()against the ISO 3166 / ISO 4217 lists.str.upper()maps some non-ASCII letters onto ASCII ones, so values that are not ISO codes are accepted:currency("uſd", ignore_case=True)returnsTrue(long s, becomesUSD)currency("ıls", ignore_case=True)returnsTrue(dotless i, becomesILS)country_code("ıt", ignore_case=True)returnsTrue(becomesIT)country_code("ıta", ignore_case=True)returnsTrue(becomesITA)country_code("fiN", iso_format="alpha3", ignore_case=True)returnsTrue(the 2-character value becomesFIN)This is the same class of issue that was fixed for IBANs in #512. The fix requires ASCII input before the case-insensitive lookup. ASCII codes in any case, and the currency symbol check (
skip_symbols=False), behave as before.The new parametrized test cases fail before this change and pass after it. The full suite passes (1522 tests, plus 58 doctests), and
ruff check,ruff format --checkandpyrightare clean on the changed files.