Merge lp:~jcsackett/launchpad/linkifier-bugs into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Māris Fogels
Approved revision: no longer in the source branch.
Merged at revision: 12073
Proposed branch: lp:~jcsackett/launchpad/linkifier-bugs
Merge into: lp:launchpad
Diff against target: 64 lines (+39/-2)
2 files modified
lib/lp/app/browser/stringformatter.py (+1/-1)
lib/lp/app/browser/tests/test_stringformatter.py (+38/-1)
To merge this branch: bzr merge lp:~jcsackett/launchpad/linkifier-bugs
Reviewer Review Type Date Requested Status
Māris Fogels (community) Approve
Review via email: mp+43677@code.launchpad.net

Commit message

[r=mars][ui=none][bug=85470,179868,276726] Updates the protocols recognized by the linkifier. file:// no longer supported, apt://, apt: and data: added.

Description of the change

Summary
=======

Several simple bugs have been filed against the linkifier in bug comments regarding its handling of various protocols. These are handled in this branch by simple changes to the protocol section of the regex used in the linkifier.

Preimp-talk
===========

Spoke with Curtis Hovey.

Implementation
==============

The linkifier decides which things to link based on the protocols defined in the protocol glob of a truly massive regex in lp.app.browser.stringformatter

The protocol section is modified to support apt and data uris, and to not follow file uris, as the latter is useless to anyone but the person with the file on their computer.

Tests
=====

lp test -t test_stringformatter

QA
==

Open launchpad.dev and file a bug against any product. In the comment section, put the following:

This links: apt:some-package
As does this: apt://some-package
As does this: data:text/plain,hello
This does not: file://some/file.txt

To post a comment you must log in.
Revision history for this message
Māris Fogels (mars) wrote :

Hi J.C.,

An excellent change, r=mars

I am surprised you have to use the DatabaseFunctionalLayer. The formatter objects must be doing a lot of work? Could we get away with just Zope registry, or even less, in this test?

Maris

review: Approve
Revision history for this message
j.c.sackett (jcsackett) wrote :

On Dec 14, 2010, at 2:21 PM, Māris Fogels wrote:
> I am surprised you have to use the DatabaseFunctionalLayer. The formatter objects must be doing a lot of work? Could we get away with just Zope registry, or even less, in this test?

Actually, no layer is needed. I am just incredibly used to typing layer=DatabaseFunctionalLayer.

I've whacked the layer and everything is still dandy. Thanks for catching that.

//j.c.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/stringformatter.py'
2--- lib/lp/app/browser/stringformatter.py 2010-10-22 03:35:41 +0000
3+++ lib/lp/app/browser/stringformatter.py 2010-12-14 20:00:39 +0000
4@@ -360,7 +360,7 @@
5 _re_linkify = re.compile(r'''
6 (?P<url>
7 \b
8- (?:about|gopher|http|https|sftp|news|ftp|mailto|file|irc|jabber)
9+ (?:about|gopher|http|https|sftp|news|ftp|mailto|irc|jabber|apt|data)
10 :
11 (?:
12 (?:
13
14=== modified file 'lib/lp/app/browser/tests/test_stringformatter.py'
15--- lib/lp/app/browser/tests/test_stringformatter.py 2010-10-04 19:50:45 +0000
16+++ lib/lp/app/browser/tests/test_stringformatter.py 2010-12-14 20:00:39 +0000
17@@ -107,9 +107,46 @@
18 <tag>1234567890123456</tag>
19 """
20
21+class TestLinkifyingProtocols(TestCase):
22+
23+ def test_apt_is_linked(self):
24+ test_string = 'This becomes a link: apt:some-package'
25+ html = FormattersAPI(test_string).text_to_html()
26+ expected_html = (
27+ '<p>This becomes a link: '
28+ '<a rel="nofollow" '
29+ 'href="apt:some-package">apt:some-<wbr></wbr>package</a></p>')
30+ self.assertEqual(expected_html, html)
31+
32+ # Do it again for apt://
33+ test_string = 'This becomes a link: apt://some-package'
34+ html = FormattersAPI(test_string).text_to_html()
35+ expected_html = (
36+ '<p>This becomes a link: '
37+ '<a rel="nofollow" '
38+ 'href="apt://some-package">apt://some-<wbr></wbr>package</a></p>')
39+ self.assertEqual(expected_html, html)
40+
41+ def test_file_is_not_linked(self):
42+ test_string = "This doesn't become a link: file://some/file.txt"
43+ html = FormattersAPI(test_string).text_to_html()
44+ expected_html = (
45+ "<p>This doesn't become a link: "
46+ "file://<wbr></wbr>some/file.<wbr></wbr>txt</p>")
47+ self.assertEqual(expected_html, html)
48+
49+ def test_data_is_linked(self):
50+ test_string = "This becomes a link: data:text/plain,test"
51+ html = FormattersAPI(test_string).text_to_html()
52+ expected_html = (
53+ "<p>This becomes a link: "
54+ '<a rel="nofollow" '
55+ 'href="data:text/plain,test">data:text/<wbr></wbr>plain,test</a></p>')
56+ self.assertEqual(expected_html, html)
57+
58
59 class TestDiffFormatter(TestCase):
60- """Test the string formtter fmt:diff."""
61+ """Test the string formatter fmt:diff."""
62 layer = DatabaseFunctionalLayer
63
64 def test_emptyString(self):