fix parsing SRV result with idna names. Fixes #4194
This commit is contained in:
		
							parent
							
								
									aa6c163506
								
							
						
					
					
						commit
						b5b27227ea
					
				
					 2 changed files with 18 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -119,13 +119,23 @@ def parse_jid(jidstring):
 | 
			
		|||
	return prep(*decompose_jid(jidstring))
 | 
			
		||||
 | 
			
		||||
def idn_to_ascii(host):
 | 
			
		||||
	'''convert IDN (Internationalized Domain Names) to ACE (ASCII-compatible encoding)'''
 | 
			
		||||
	'''convert IDN (Internationalized Domain Names) to ACE
 | 
			
		||||
	(ASCII-compatible encoding)'''
 | 
			
		||||
	labels = idna.dots.split(host)
 | 
			
		||||
	converted_labels = []
 | 
			
		||||
	for label in labels:
 | 
			
		||||
		converted_labels.append(idna.ToASCII(label))
 | 
			
		||||
	return ".".join(converted_labels)
 | 
			
		||||
 | 
			
		||||
def ascii_to_idn(host):
 | 
			
		||||
	'''convert ACE (ASCII-compatible encoding) to IDN
 | 
			
		||||
	(Internationalized Domain Names)'''
 | 
			
		||||
	labels = idna.dots.split(host)
 | 
			
		||||
	converted_labels = []
 | 
			
		||||
	for label in labels:
 | 
			
		||||
		converted_labels.append(idna.ToUnicode(label))
 | 
			
		||||
	return ".".join(converted_labels)
 | 
			
		||||
 | 
			
		||||
def parse_resource(resource):
 | 
			
		||||
	'''Perform stringprep on resource and return it'''
 | 
			
		||||
	if resource:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -109,13 +109,19 @@ class Resolver:
 | 
			
		|||
		# _xmpp-client._tcp.jabber.org    service = 30 30 5222 jabber.org.
 | 
			
		||||
		if not result: 
 | 
			
		||||
			return []
 | 
			
		||||
		ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name
 | 
			
		||||
		hosts = []
 | 
			
		||||
		lines = result.split('\n')
 | 
			
		||||
		for line in lines:
 | 
			
		||||
			if line == '':
 | 
			
		||||
				continue
 | 
			
		||||
			domain = None
 | 
			
		||||
			if line.startswith(fqdn):
 | 
			
		||||
				rest = line[len(fqdn):].split('=')
 | 
			
		||||
				domain = fqdn
 | 
			
		||||
			elif line.startswith(ufqdn):
 | 
			
		||||
				domain = ufqdn
 | 
			
		||||
			if domain:
 | 
			
		||||
				rest = line[len(host):].split('=')
 | 
			
		||||
				if len(rest) != 2:
 | 
			
		||||
					continue
 | 
			
		||||
				answer_type, props_str = rest
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue