From c7eaec27d802a3231b312d0ace2fd988b2e0544e Mon Sep 17 00:00:00 2001 From: Bernward Sanchez Date: Fri, 23 Dec 2022 08:23:14 +0800 Subject: [PATCH 1/2] Update utils.py --- powerdnsadmin/lib/utils.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index 9a528dd..769587e 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -238,24 +238,22 @@ class customBoxes: } order = ["reverse", "ip6arpa", "inaddrarpa"] -def pretty_domain_name(value): - """ - Display domain name in original format. - If it is IDN domain (Punycode starts with xn--), do the - idna decoding. - Note that any part of the domain name can be individually punycoded - """ - if isinstance(value, str): - if value.startswith('xn--') \ - or value.find('.xn--') != -1: - try: - return to_idna(value, 'decode') - except: - raise Exception('Cannot decode IDN domain') - else: - return value - else: - raise Exception('Require the Punycode in string format') +def pretty_domain_name(domain_name): + # Add a debugging statement to print out the domain name + print("Received domain name:", domain_name) + + # Check if the domain name is encoded using Punycode + if domain_name.endswith('.xn--'): + try: + # Decode the domain name using the idna library + domain_name = idna.decode(domain_name) + except Exception as e: + # If the decoding fails, raise an exception with more information + raise Exception('Cannot decode IDN domain: {}'.format(e)) + + # Return the "pretty" version of the domain name + return domain_name + def to_idna(value, action): splits = value.split('.') From b163e517bb56596adf28df691076d1160630da8f Mon Sep 17 00:00:00 2001 From: Bernward Sanchez Date: Mon, 9 Jan 2023 11:10:22 +0800 Subject: [PATCH 2/2] Update utils.py