From fd12451f5acc4e0ad94b66d61aad6540abb9840a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 25 Jan 2021 12:24:40 +0000 Subject: [PATCH] Tests for international domain handling --- tests.py | 15 +++++++++++++++ utils.py | 11 +++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests.py b/tests.py index 2bebb1f2c..d87d1229c 100644 --- a/tests.py +++ b/tests.py @@ -33,6 +33,7 @@ from follow import clearFollows from follow import clearFollowers from follow import sendFollowRequestViaServer from follow import sendUnfollowRequestViaServer +from utils import decodedHost from utils import getFullDomain from utils import validNickname from utils import firstParagraphFromString @@ -3059,9 +3060,23 @@ def testMastoApi(): assert nickname2 == nickname +def testDomainHandling(): + print('testDomainHandling') + testDomain = 'localhost' + assert decodedHost(testDomain) == testDomain + testDomain = '127.0.0.1:60' + assert decodedHost(testDomain) == testDomain + testDomain = '192.168.5.153' + assert decodedHost(testDomain) == testDomain + testDomain = 'xn--espaa-rta.icom.museum' + print(decodedHost(testDomain)) + assert decodedHost(testDomain) == "espaƱa.icom.museum" + + def runAllTests(): print('Running tests...') testFunctions() + testDomainHandling() testMastoApi() testLinksWithinPost() testReplyToPublicPost() diff --git a/utils.py b/utils.py index 232adfa55..4ca5350f1 100644 --- a/utils.py +++ b/utils.py @@ -36,12 +36,11 @@ def decodedHost(host: str) -> str: https://en.wikipedia.org/wiki/Internationalized_domain_name """ if ':' not in host: - if not _localNetworkHost(host): - if not host.endswith('.onion'): - if not host.endswith('.i2p'): - # For domains on ports numbers don't use idna - # eg. mydomain:8000 - return idna.decode(host) + # eg. mydomain:8000 + if not _localNetworkHost(host): + if not host.endswith('.onion'): + if not host.endswith('.i2p'): + return idna.decode(host) return host