Repository navigation
Look up the IDNA-encoded TLD when consider_tld is set - #523
Open
DevKaurav-14 wants to merge 1 commit into
Open
DevKaurav-14 wants to merge 1 commit into
DevKaurav-14 wants to merge 1 commit into
Conversation
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
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.
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()andurl()inherited this throughdomain().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 (пример.рф,пример.рф.withrfc_1034,例子.中国) pass, and an unknown Unicode TLD (пример.рфы) fails.test_hostname.py,test_url.py: newconsider_tldcases for ASCII, punycode and Unicode TLDs, valid and invalid.The new tests fail without the fix.
ruff check,ruff format --checkandpyrightare clean.