Skip to content

fix(codes): allow whitespace around currency, country and language codes - #451

Merged
yezz123 merged 1 commit into
pydantic:mainfrom
RavSinghChandan:code-types-strip-whitespace
Oct 18, 2026
Merged

yezz123 merged 1 commit into
pydantic:mainfrom
RavSinghChandan:code-types-strip-whitespace

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

The currency, country and language code types already accept any letter case ("usd" gives "USD", "in" gives "IN"), but a value with surrounding whitespace, such as " USD " or "India\n", was rejected. For currencies the message was even misleading: "String should have at most 3 characters". PaymentCardNumber and ABARoutingNumber already strip whitespace through their string schema.

The string schemas of ISO4217, Currency, CountryAlpha2, CountryAlpha3, CountryNumericCode, CountryShortName, LanguageAlpha2, LanguageName, ISO639_3 and ISO639_5 now set strip_whitespace=True, the same way. Whitespace inside a code is still rejected, and whitespace-only input is still invalid (the existing printable cases cover it). Added whitespace cases to the currency tests and a test for each country and language type.

@yezz123
yezz123 merged commit bd2821f into pydantic:main Oct 18, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants