Skip to content

Look up the IDNA-encoded TLD when consider_tld is set - #523

Open
DevKaurav-14 wants to merge 1 commit into
python-validators:masterfrom
DevKaurav-14:fix/idn-tld-consider-tld
Open

DevKaurav-14 wants to merge 1 commit into
python-validators:masterfrom
DevKaurav-14:fix/idn-tld-consider-tld

Conversation

@DevKaurav-14

Copy link
Copy Markdown

Fixes #522

What was wrong

With consider_tld=True, domain() looked up the raw TLD in the IANA list. The list stores IDN TLDs in punycode, so Unicode TLDs such as .рф or .中国 were always rejected. hostname() and url() inherited this through domain().

Change

The TLD check now runs after IDNA encoding and uses the encoded TLD. Nothing else in the validation changes.

Tests

  • test_domain.py: Unicode TLDs (пример.рф, пример.рф. with rfc_1034, 例子.中国) pass, and an unknown Unicode TLD (пример.рфы) fails.
  • test_hostname.py, test_url.py: new consider_tld cases for ASCII, punycode and Unicode TLDs, valid and invalid.

The new tests fail without the fix. ruff check, ruff format --check and pyright are clean.

The IANA list stores internationalized TLDs in punycode (XN--P1AI),
but domain() checked the raw Unicode TLD against it. Unicode domains
such as пример.рф were rejected with consider_tld=True while their
punycode form was accepted. hostname() and url() inherit this through
domain().

Run the TLD check after IDNA encoding, on the encoded TLD.

This branch has not been deployed

No deployments
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.

consider_tld rejects Unicode IDN TLDs (e.g. пример.рф)

1 participant