From 00b46e05752ed5e8e98b0256ce34070ea71dfb17 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 9 Apr 2019 20:43:16 +0200 Subject: [PATCH] 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. --- src/opnsense/service/modules/template.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/opnsense/service/modules/template.py b/src/opnsense/service/modules/template.py index 02dcb1c35..153604763 100644 --- a/src/opnsense/service/modules/template.py +++ b/src/opnsense/service/modules/template.py @@ -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