@@ 91,7 91,8 @@ class UrlizePattern(markdown.inlinepatterns.Pattern):
to standard matching flags added by parent class.
"""
- return re.compile(r'^(.*?)%s(.*?)$' % URLIZE_RE, re.DOTALL | re.UNICODE | re.IGNORECASE)
+ # Ensure links are matched only if they stand on their own to avoid bad matches etc.
+ return re.compile(r'^(|.*?\s)%s(\s.*?|)$' % URLIZE_RE, re.DOTALL | re.UNICODE | re.IGNORECASE)
def handleMatch(self, m):
"""
@@ 120,6 120,24 @@ FIXTURE_POSITIVE_MATCHES = [
'http://example.com/my/path?param1=value1¶m2=value2',
EXPECTED_PARAGRAPH_TEMPLATE % ('http://example.com/my/path?param1=value1&param2=value2', 'http://example.com/my/path?param1=value1&param2=value2')
),
+
+ # Link positioned somewhere within the text, but around whitespace boundary.
+ (
+ 'This is link myhost.example.com',
+ "<p>This is link " + EXPECTED_LINK_TEMPLATE % ('http://myhost.example.com', 'myhost.example.com') + "</p>"
+ ),
+ (
+ 'myhost.example.com is the link',
+ "<p>" + EXPECTED_LINK_TEMPLATE % ('http://myhost.example.com', 'myhost.example.com') + " is the link</p>"
+ ),
+ (
+ 'I have best myhost.example.com link ever',
+ "<p>I have best " + EXPECTED_LINK_TEMPLATE % ('http://myhost.example.com', 'myhost.example.com') + " link ever</p>"
+ ),
+ (
+ 'I have best\nmyhost.example.com link ever',
+ "<p>I have best\n" + EXPECTED_LINK_TEMPLATE % ('http://myhost.example.com', 'myhost.example.com') + " link ever</p>"
+ ),
]
@@ 139,6 157,14 @@ FIXTURE_NEGATIVE_MATCHES = [
'example-.com',
'<p>example-.com</p>'
),
+ (
+ '-example.com',
+ '<p>-example.com</p>'
+ ),
+ (
+ 'my.-example.com',
+ '<p>my.-example.com</p>'
+ ),
]