From 52ee5166619d191ead8a5dd54e4fe08a905564de Mon Sep 17 00:00:00 2001 From: Branko Majic Date: Wed, 21 Feb 2018 20:27:16 +0100 Subject: [PATCH] Expand tests for custom urlize markdown extension: - Add some testing for invalid patterns (thing that should not produce link, although they look a bit like that). - Optimized regex for IPv6 form slightly. --- src/wiki/plugins/links/mdx/urlize.py | 2 +- tests/plugins/links/test_urlize.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/wiki/plugins/links/mdx/urlize.py b/src/wiki/plugins/links/mdx/urlize.py index 901ce1c2..fe487628 100644 --- a/src/wiki/plugins/links/mdx/urlize.py +++ b/src/wiki/plugins/links/mdx/urlize.py @@ -63,7 +63,7 @@ URLIZE_RE = ( r'(?P' # begin host identifier group r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|' # IPv4, match before FQDN - r'\[?[A-F0-9]{1,4}:([A-F0-9]{1,4}:){6}[A-F0-9]{1,4}\]?|' # IPv6, full form + r'\[?([A-F0-9]{1,4}:){7}([A-F0-9]{1,4})\]?|' # IPv6, full form r'\[?:(:[A-F0-9]{1,4}){1,6}\]?|' # IPv6, leading zeros removed r'([A-F0-9]{1,4}:){1,6}:([A-F0-9]{1,4}){1,6}|' # IPv6, zeros in middle removed. r'\[?([A-F0-9]{1,4}:){1,6}:\]?|' # IPv6, trailing zeros removed diff --git a/tests/plugins/links/test_urlize.py b/tests/plugins/links/test_urlize.py index 37750eef..d77e4017 100644 --- a/tests/plugins/links/test_urlize.py +++ b/tests/plugins/links/test_urlize.py @@ -152,6 +152,12 @@ FIXTURE_NEGATIVE_MATCHES = [ '

.example .com

' ), + # localhost as part of another word. + ( + 'localhosts', + '

localhosts

' + ), + # Invalid FQDNs. ( 'example-.com', @@ -165,6 +171,31 @@ FIXTURE_NEGATIVE_MATCHES = [ 'my.-example.com', '

my.-example.com

' ), + + # Invalid IPv6 patterns. + ( + '1:2:3:4:5:6:7:8:a', # Use :a, because using a number would match as optional port + '

1:2:3:4:5:6:7:8:a

', + ), + ( + '1::2::3', + '

1::2::3

', + ), + ( + '::::1', + '

::::1

', + ), + ( + '1::::', + '

1::::

', + ), + + # Invalid IPv4 patterns. + ( + '1.2.3.4.5', + '

1.2.3.4.5

', + ), + ] -- 2.45.2