configd, idna encode, orginating from https://github.com/opnsense/core/pull/3107 and other commits from the same contributor.

Fix for https://github.com/opnsense/core/pull/3107, although I'm doubting if we should keep supporting idna, since fixing these issues often cost us quite some time and demand for the feature doesn't appear to be very high.
This commit is contained in:
Ad Schellevis 2019-04-09 20:43:16 +02:00
parent ba2380a397
commit 00b46e0575

View File

@ -67,8 +67,13 @@ class Template(object):
def _encode_idna(x):
""" encode string to idna, preserve leading dots
"""
tmp = b''.join([b''.join([b'.' for x in range(len(x) - len(x.lstrip('.')))]), x.lstrip('.').encode('idna')])
return tmp.decode()
try:
tmp = b''.join([b''.join([b'.' for x in range(len(x) - len(x.lstrip('.')))]), x.lstrip('.').encode('idna')])
return tmp.decode()
except UnicodeError:
# return source when unable to decode
syslog.syslog(syslog.LOG_NOTICE, "encode idna: unable to decode %s, return source" % x)
return x
def list_module(self, module_name):
""" list single module content