jid: Improve error reporting on IDNA validation failure

At least knowing the failing domain should help a lot while debugging.
This commit is contained in:
Emmanuel Gil Peyrot 2021-11-18 15:33:37 +01:00
parent d4067275ff
commit ed514e6f73

View file

@ -133,15 +133,15 @@ def _validate_domain(domain: str):
try: try:
domain = idna(domain) domain = idna(domain)
except StringprepError: except StringprepError:
raise InvalidJID('idna validation failed') raise InvalidJID(f'idna validation failed: {domain}')
if ':' in domain: if ':' in domain:
raise InvalidJID('Domain containing a port') raise InvalidJID(f'Domain containing a port: {domain}')
for label in domain.split('.'): for label in domain.split('.'):
if not label: if not label:
raise InvalidJID('Domain containing too many dots') raise InvalidJID(f'Domain containing too many dots: {domain}')
if '-' in (label[0], label[-1]): if '-' in (label[0], label[-1]):
raise InvalidJID('Domain started or ended with -') raise InvalidJID(f'Domain starting or ending with -: {domain}')
if not domain: if not domain:
raise InvalidJID('Domain must not be 0 bytes') raise InvalidJID('Domain must not be 0 bytes')