Skip to content
Snippets Groups Projects
Commit 9c23901c authored by Moul's avatar Moul
Browse files

[enh] #170: Change domain regex to support IDN

Internationalized domain names
Add test
parent e7455f29
No related branches found
No related tags found
2 merge requests!157v1.0.0rc0: merge dev into master,!145#170: Endpoints' regex improvement
...@@ -40,7 +40,11 @@ IPV6_REGEX = ( ...@@ -40,7 +40,11 @@ IPV6_REGEX = (
f"fe80:(?::{IPV6SEG}){{0,4}}%[0-9a-zA-Z]+|::(?:ffff(?::0{{1,4}})?:)?{IPV4_REGEX}|" f"fe80:(?::{IPV6SEG}){{0,4}}%[0-9a-zA-Z]+|::(?:ffff(?::0{{1,4}})?:)?{IPV4_REGEX}|"
f"(?:{IPV6SEG}:){{1,4}}:{IPV4_REGEX}" f"(?:{IPV6SEG}:){{1,4}}:{IPV4_REGEX}"
) )
HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?" # https://stackoverflow.com/a/26987741
HOST_REGEX = (
"(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]\\.)*"
"(xn--)?([a-z0-9][a-z0-9\\-]{0,60}|[a-z0-9-]{1,30}\\.[a-z]{2,})"
)
# https://stackoverflow.com/a/12968117 # https://stackoverflow.com/a/12968117
PORT_REGEX = ( PORT_REGEX = (
"[1-9]\\d{0,3}|0|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]" "[1-9]\\d{0,3}|0|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]"
......
...@@ -46,6 +46,19 @@ class TestEndpoint(unittest.TestCase): ...@@ -46,6 +46,19 @@ class TestEndpoint(unittest.TestCase):
self.assertEqual(gva_endpoint.inline(), endpoint_str) self.assertEqual(gva_endpoint.inline(), endpoint_str)
endpoint_str = "GVA S xn--duniter.org 10902"
gva_endpoint = endpoint.GVAEndpoint.from_inline(endpoint_str)
self.assertEqual(gva_endpoint.flags, "S")
self.assertEqual(gva_endpoint.server, "xn--duniter.org")
self.assertEqual(gva_endpoint.ipv4, None)
self.assertEqual(gva_endpoint.ipv6, None)
self.assertEqual(gva_endpoint.port, 10902)
self.assertEqual(gva_endpoint.path, "")
self.assertEqual(gva_endpoint.inline(), endpoint_str)
def test_gva_subscription(self): def test_gva_subscription(self):
endpoint_str = "GVASUB test.domain.com 127.0.0.1 2001:0db8:0000:85a3:0000:0000:ac1f:8001 10902 gva" endpoint_str = "GVASUB test.domain.com 127.0.0.1 2001:0db8:0000:85a3:0000:0000:ac1f:8001 10902 gva"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment