Commit 78ebaefa authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Dont punycode encode all domain names

RFC7622 3.2.1

... This implies that the string MUST NOT include A-labels ...

Fixes #9211
parent 86eddc2e
...@@ -61,12 +61,6 @@ ...@@ -61,12 +61,6 @@
except ImportError: except ImportError:
HAS_PRECIS_I18N = False HAS_PRECIS_I18N = False
try:
import idna
HAS_IDNA = True
except ImportError:
HAS_IDNA = False
HAS_SOUND = True HAS_SOUND = True
if sys.platform == 'win32': if sys.platform == 'win32':
try: try:
...@@ -291,16 +285,13 @@ def prep(user, server, resource): ...@@ -291,16 +285,13 @@ def prep(user, server, resource):
if not ip_address: if not ip_address:
if server is not None: if server is not None:
if server.endswith('.'): # RFC7622, 3.2 if server.endswith('.'): # RFC7622, 3.2
server = server[:-1] server = server[:-1]
if len(server) < 1 or len(server.encode('utf-8')) > 1023: if len(server) < 1 or len(server.encode('utf-8')) > 1023:
raise InvalidFormat(_('Server must be between 1 and 1023 bytes')) raise InvalidFormat(_('Server must be between 1 and 1023 bytes'))
try: try:
if HAS_IDNA: from nbxmpp.stringprepare import nameprep
server = idna.encode(server).decode('utf-8') server = nameprep.prepare(server)
else:
from nbxmpp.stringprepare import nameprep
server = nameprep.prepare(server)
except UnicodeError: except UnicodeError:
raise InvalidFormat(_('Invalid character in hostname.')) raise InvalidFormat(_('Invalid character in hostname.'))
else: else:
......
Markdown is supported
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