kjd / idna

Internationalized Domain Names for Python (IDNA 2008 and UTS #46)
BSD 3-Clause "New" or "Revised" License
247 stars 91 forks source link

Implement is_idna #158

Closed elliotwutingfeng closed 9 months ago

elliotwutingfeng commented 9 months ago

Closes #149.

Assumption: Does idna.encode() always throw an exception for strings that contain invalid punycode and/or unconvertible unicode (such as emojis)?


is_idna(s) returns True if a given string s can be encoded by idna.encode() without error, and at least one of its encoded labels begins with b"xn--".

A more efficient implementation would be to reuse portions of idna.encode() so that the per-label b"xn--" checks can be done before doing s = b'.'.join(result) for the final valid_string_length() check.

kjd commented 9 months ago

I'm reluctant to merge this PR. Only one person has asked for this functionality and hasn't even confirmed in their issue that this is even what they are looking for. Given it is only subtly different from using encode() for the same purpose I am not sure it is worth adding this new function.

elliotwutingfeng commented 9 months ago

Alright, I think this should be closed for now and left for future reference.