summaryrefslogtreecommitdiff
path: root/slixmpp/jid.py
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-06-12 00:56:52 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-06-12 11:52:48 +0100
commitf3e31baf04db7926e912e687a544b93c2547363e (patch)
tree18fc76c03d6f03edd0c16b8548d74b609d01286a /slixmpp/jid.py
parenta2852eb249d443e7aef4281bba5243db8a40c837 (diff)
downloadslixmpp-f3e31baf04db7926e912e687a544b93c2547363e.tar.gz
slixmpp-f3e31baf04db7926e912e687a544b93c2547363e.tar.bz2
slixmpp-f3e31baf04db7926e912e687a544b93c2547363e.tar.xz
slixmpp-f3e31baf04db7926e912e687a544b93c2547363e.zip
Properly consider malformed IPv6 domains as invalid.
Diffstat (limited to 'slixmpp/jid.py')
-rw-r--r--slixmpp/jid.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/slixmpp/jid.py b/slixmpp/jid.py
index 1df7d1f0..8a1530c3 100644
--- a/slixmpp/jid.py
+++ b/slixmpp/jid.py
@@ -30,6 +30,8 @@ ILLEGAL_CHARS = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r' + \
'\x1a\x1b\x1c\x1d\x1e\x1f' + \
' !"#$%&\'()*+,./:;<=>?@[\\]^_`{|}~\x7f'
+HAVE_INET_PTON = hasattr(socket, 'inet_pton')
+
#: The basic regex pattern that a JID must match in order to determine
#: the local, domain, and resource parts. This regex does NOT do any
#: validation, which requires application of nodeprep, resourceprep, etc.
@@ -199,10 +201,10 @@ def _validate_domain(domain):
pass
# Check if this is an IPv6 address
- if not ip_addr and hasattr(socket, 'inet_pton'):
+ if not ip_addr and HAVE_INET_PTON and domain[0] == '[' and domain[-1] == ']':
try:
- socket.inet_pton(socket.AF_INET6, domain.strip('[]'))
- domain = '[%s]' % domain.strip('[]')
+ ip = domain[1:-1]
+ socket.inet_pton(socket.AF_INET6, ip)
ip_addr = True
except (socket.error, ValueError):
pass