Repository navigation
fix(validators): respect empty allowed_domains list in EmailValidator - #2422
waketzheng merged 3 commits into
Conversation
Merging this PR will not alter performance1 warning
Comparing |
…mail-validator-empty-allowed-domains
|
Leaving a note here for anyone reviewing this later or tracing the change via
The alternative — keeping |
Description
This PR fixes
EmailValidatorignoring an explicitly emptyallowed_domainslist (allowed_domains=[]). With this fix:allowed_domains=[]blocks all domains (raisingInvalidEmailAddress), consistent withURLValidator(allowed_schemes=[])fixed in Respect empty URL scheme allowlists #2394.allowed_domainsor passingNonepreserves default syntax validation across all valid domains.Motivation and Context
EmailValidatorpreviously initializedself.allowed_domains = [i.lower() for i in allowed_domains or ()]. Whenallowed_domains=[]was provided,bool(self.allowed_domains)evaluated toFalsein__call__, falling back to standard domain syntax validation and accepting any valid domain instead of enforcing the empty allowlist.This brings symmetry with #2394 (
URLValidator), where empty allowlists block all schemes.How Has This Been Tested?
pytest tests/test_validators.py(83 passed).test_email_validator_rejects_all_domains_when_allowlist_is_emptycovering bothEmailValidator([])andEmailValidator(allowed_domains=[]).ruff checkandruff format --checkclean.mypytype checking clean.Checklist: