~netlandish/django-wiki

52ee5166619d191ead8a5dd54e4fe08a905564de — Branko Majic 6 years ago e041a77
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.
2 files changed, 32 insertions(+), 1 deletions(-)

M src/wiki/plugins/links/mdx/urlize.py
M tests/plugins/links/test_urlize.py
M src/wiki/plugins/links/mdx/urlize.py => src/wiki/plugins/links/mdx/urlize.py +1 -1
@@ 63,7 63,7 @@ URLIZE_RE = (
    r'(?P<host>'  # 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

M tests/plugins/links/test_urlize.py => tests/plugins/links/test_urlize.py +31 -0
@@ 152,6 152,12 @@ FIXTURE_NEGATIVE_MATCHES = [
        '<p>.example .com</p>'
    ),

    # localhost as part of another word.
    (
        'localhosts',
        '<p>localhosts</p>'
    ),

    # Invalid FQDNs.
    (
        'example-.com',


@@ 165,6 171,31 @@ FIXTURE_NEGATIVE_MATCHES = [
        'my.-example.com',
        '<p>my.-example.com</p>'
    ),

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

    # Invalid IPv4 patterns.
    (
        '1.2.3.4.5',
        '<p>1.2.3.4.5</p>',
    ),

]