Commit 1b7abc6d authored by Philipp Hörist's avatar Philipp Hörist
Browse files

fix: Prepare domain names with UTS46

parent 4597ea9c
Pipeline #10825 failed with stages
in 24 seconds
......@@ -521,7 +521,7 @@ def validate_domainpart(domainpart: str) -> str:
domainpart = domainpart[:-1]
try:
idna_encode(domainpart)
domainpart = idna2008_prep(domainpart)
except Exception:
raise DomainpartNotAllowedChar
......@@ -529,8 +529,16 @@ def validate_domainpart(domainpart: str) -> str:
@functools.lru_cache(maxsize=None)
def idna_encode(domain: str) -> str:
return idna.encode(domain, uts46=True).decode()
def idna2008_prep(domain: str) -> str:
'''
Prepare with UTS46 case mapping to stay compatibel with the IDNA2003
mapping. Further try to encode the domain to catch illegal domains.
Only return the case mapped domain because on the XMPP wire,UTF8 domains
are fine.
'''
domain = idna.uts46_remap(domain)
idna.encode(domain)
return domain
@functools.lru_cache(maxsize=None)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment