From 97a79645b00d1d425f810e1b56b6cb721d81746b Mon Sep 17 00:00:00 2001 From: Dominik Fahr Date: Mon, 12 Dec 2022 17:31:32 +0100 Subject: [PATCH] fix of issue #1261 split record by "." idna.encode leads into full stop if the string starts with "_" or "-" --- powerdnsadmin/lib/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index 9e7cf20..9a528dd 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -258,18 +258,24 @@ def pretty_domain_name(value): raise Exception('Require the Punycode in string format') def to_idna(value, action): - splits = value.split() + splits = value.split('.') result = [] if action == 'encode': for split in splits: try: # Try encoding to idna - result.append(idna.encode(split).decode()) + if not split.startswith('_') and not split.startswith('-'): + result.append(idna.encode(split).decode()) + else: + result.append(split) except idna.IDNAError: result.append(split) elif action == 'decode': for split in splits: - result.append(idna.decode(split)) + if not split.startswith('_') and not split.startswith('--'): + result.append(idna.decode(split)) + else: + result.append(split) else: raise Exception('No valid action received') - return ' '.join(result) + return '.'.join(result)