Merge lp:~robru/friends/dont-linkify-doctype into lp:friends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Robert Bruce Park
Approved revision: 212
Merged at revision: 212
Proposed branch: lp:~robru/friends/dont-linkify-doctype
Merge into: lp:friends
Diff against target: 59 lines (+18/-8)
2 files modified
friends/tests/test_protocols.py (+11/-0)
friends/utils/base.py (+7/-8)
To merge this branch: bzr merge lp:~robru/friends/dont-linkify-doctype
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Robert Bruce Park Approve
Review via email: mp+170900@code.launchpad.net

Commit message

Don't linkify URLs inside the DOCTYPE.

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

Excellent test coverage!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'friends/tests/test_protocols.py'
2--- friends/tests/test_protocols.py 2013-04-05 00:32:04 +0000
3+++ friends/tests/test_protocols.py 2013-06-21 20:19:32 +0000
4@@ -516,8 +516,19 @@
5 '<a href="www.example.com">www.example.com</a> is our website',
6 linkify_string(
7 '<a href="www.example.com">www.example.com</a> is our website'))
8+ self.assertEqual(
9+ "<a href='www.example.com'>www.example.com</a> is our website",
10+ linkify_string(
11+ "<a href='www.example.com'>www.example.com</a> is our website"))
12 # This, apparently, is valid HTML.
13 self.assertEqual(
14 '<a href = "www.example.com">www.example.com</a>',
15 linkify_string(
16 '<a href = "www.example.com">www.example.com</a>'))
17+ # Pump.io is throwing doctypes at us!
18+ self.assertEqual(
19+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" '
20+ '"http://www.w3.org/TR/REC-html40/strict.dtd">',
21+ linkify_string(
22+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" '
23+ '"http://www.w3.org/TR/REC-html40/strict.dtd">'))
24
25=== modified file 'friends/utils/base.py'
26--- friends/utils/base.py 2013-05-29 17:34:02 +0000
27+++ friends/utils/base.py 2013-06-21 20:19:32 +0000
28@@ -56,9 +56,9 @@
29 # See friends/tests/test_protocols.py for further documentation
30 LINKIFY_REGEX = re.compile(
31 r"""
32- # Do not match if URL is preceded by '"' or '>'
33+ # Do not match if URL is preceded by quotes, slash, or '>'
34 # This is used to prevent duplication of linkification.
35- (?<![\"\>])
36+ (?<![\'\"\>/])
37 # Record everything that we're about to match.
38 (
39 # URLs can start with 'http://', 'https://', 'ftp://', or 'www.'
40@@ -70,15 +70,14 @@
41 # This section will peek ahead (without matching) in order to
42 # determine precisely where the URL actually *ends*.
43 (?=
44- # Do not include any trailing period, comma, exclamation mark,
45- # question mark, or closing parentheses, if any are present.
46- [.,!?\)]*
47+ # Do not include any trailing punctuation, if any are present.
48+ [.,!?\"\'\)\<\>]*
49 # With "trailing" defined as immediately preceding the first
50 # space, or end-of-string.
51 (?:\s|$)
52- # But abort the whole thing if the URL ends with '</a>',
53- # again to prevent duplication of linkification.
54- (?!</a>)
55+ # But abort the whole thing if the URL ends with a quote or angle
56+ # bracket, again to prevent duplication of linkification.
57+ (?![\'\"\<\>]+)
58 )""",
59 flags=re.VERBOSE).sub
60

Subscribers

People subscribed via source and target branches