diff options
author | lovetox <philipp@hoerist.com> | 2022-08-29 19:10:13 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-08-29 19:10:13 +0300 |
commit | 883361d4ffd173130cfd2848e3df434b86054289 (patch) | |
tree | 5c59cc897c124146ed48ff7a5d85d7a43f97adab | |
parent | 1b7abc6de619bc331a2d57e621511dd3be27b982 (diff) |
cfix: Allow encoding domains to ascii
-rw-r--r-- | nbxmpp/protocol.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py index 212d679..eb41a09 100644 --- a/nbxmpp/protocol.py +++ b/nbxmpp/protocol.py @@ -529,7 +529,7 @@ def validate_domainpart(domainpart: str) -> str: @functools.lru_cache(maxsize=None) -def idna2008_prep(domain: str) -> str: +def idna2008_prep(domain: str, to_ascii: bool = False) -> str: ''' Prepare with UTS46 case mapping to stay compatibel with the IDNA2003 mapping. Further try to encode the domain to catch illegal domains. @@ -537,7 +537,9 @@ def idna2008_prep(domain: str) -> str: are fine. ''' domain = idna.uts46_remap(domain) - idna.encode(domain) + encoded_domain = idna.encode(domain) + if to_ascii: + return encoded_domain.decode() return domain @@ -694,7 +696,7 @@ class JID: return not self.__eq__(other) def domain_to_ascii(self) -> str: - return idna_encode(self.domain) + return idna2008_prep(self.domain, to_ascii=True) @property def bare(self) -> str: |