Merge pull request #1340 from pneb/patch-5

patch(lib/utils.py): Fixes pretty_domain_name issue
This commit is contained in:
Matt Scott 2023-01-10 08:00:28 -05:00 committed by GitHub
commit debeda5b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,24 +238,22 @@ class customBoxes:
} }
order = ["reverse", "ip6arpa", "inaddrarpa"] order = ["reverse", "ip6arpa", "inaddrarpa"]
def pretty_domain_name(value): def pretty_domain_name(domain_name):
""" # Add a debugging statement to print out the domain name
Display domain name in original format. print("Received domain name:", domain_name)
If it is IDN domain (Punycode starts with xn--), do the
idna decoding. # Check if the domain name is encoded using Punycode
Note that any part of the domain name can be individually punycoded if domain_name.endswith('.xn--'):
"""
if isinstance(value, str):
if value.startswith('xn--') \
or value.find('.xn--') != -1:
try: try:
return to_idna(value, 'decode') # Decode the domain name using the idna library
except: domain_name = idna.decode(domain_name)
raise Exception('Cannot decode IDN domain') except Exception as e:
else: # If the decoding fails, raise an exception with more information
return value raise Exception('Cannot decode IDN domain: {}'.format(e))
else:
raise Exception('Require the Punycode in string format') # Return the "pretty" version of the domain name
return domain_name
def to_idna(value, action): def to_idna(value, action):
splits = value.split('.') splits = value.split('.')