Merge lp:~stevenk/launchpad/text_to_html-no-linkify into lp:launchpad

Proposed by Steve Kowalik on 2010-12-20
Status: Merged
Approved by: Steve Kowalik on 2010-12-20
Approved revision: no longer in the source branch.
Merged at revision: 12115
Proposed branch: lp:~stevenk/launchpad/text_to_html-no-linkify
Merge into: lp:launchpad
Diff against target: 90 lines (+34/-7)
4 files modified
lib/lp/app/browser/stringformatter.py (+5/-4)
lib/lp/app/browser/tests/test_stringformatter.py (+15/-0)
lib/lp/soyuz/browser/archive.py (+3/-2)
lib/lp/soyuz/browser/tests/archive-views.txt (+11/-1)
To merge this branch: bzr merge lp:~stevenk/launchpad/text_to_html-no-linkify
Reviewer Review Type Date Requested Status
Tim Penhey (community) 2010-12-20 Approve on 2010-12-20
Review via email: mp+44192@code.launchpad.net

Commit Message

[r=thumper][ui=none][bug=631131] Control linkification of text_to_html with a flag, and use it for probationary users PPA descriptions.

Description of the Change

Change how text_to_html can be called, by controlling linkification with a flag.

Use this flag to control how PPA descriptions are displayed. Profit.

To post a comment you must log in.
Tim Penhey (thumper) :
review: Approve

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-12-17 18:11:02 +0000
3+++ lib/lp/app/browser/stringformatter.py 2010-12-20 05:52:31 +0000
4@@ -479,7 +479,7 @@
5 # re-attaches parens if we do want them to be part of the url.
6 _re_url_trailers = re.compile(r'([,.?:);>]+)$')
7
8- def text_to_html(self):
9+ def text_to_html(self, linkify_text=True):
10 """Quote text according to DisplayingParagraphsOfText."""
11 # This is based on the algorithm in the
12 # DisplayingParagraphsOfText spec, but is a little more
13@@ -512,9 +512,10 @@
14
15 text = ''.join(output)
16
17- # Linkify the text.
18- text = re_substitute(self._re_linkify, self._linkify_substitution,
19- break_long_words, text)
20+ # Linkify the text, if allowed.
21+ if linkify_text is True:
22+ text = re_substitute(self._re_linkify, self._linkify_substitution,
23+ break_long_words, text)
24
25 return text
26
27
28=== modified file 'lib/lp/app/browser/tests/test_stringformatter.py'
29--- lib/lp/app/browser/tests/test_stringformatter.py 2010-12-17 16:13:21 +0000
30+++ lib/lp/app/browser/tests/test_stringformatter.py 2010-12-20 05:52:31 +0000
31@@ -209,6 +209,21 @@
32 'data:text/<wbr></wbr>plain,test</a></p>')
33 self.assertEqual(expected_html, html)
34
35+ def test_no_link_with_linkify_text_false(self):
36+ test_string = "This doesn't become a link: http://www.example.com/"
37+ html = FormattersAPI(test_string).text_to_html(linkify_text=False)
38+ expected_html = (
39+ "<p>This doesn't become a link: http://www.example.com/</p>")
40+ self.assertEqual(expected_html, html)
41+
42+ def test_no_link_html_code_with_linkify_text_false(self):
43+ test_string = '<a href="http://example.com/">http://example.com/</a>'
44+ html = FormattersAPI(test_string).text_to_html(linkify_text=False)
45+ expected_html = (
46+ '<p>&lt;a href="http://example.com/"&gt;'
47+ 'http://example.com/&lt;/a&gt;</p>')
48+ self.assertEqual(expected_html, html)
49+
50
51 class TestDiffFormatter(TestCase):
52 """Test the string formatter fmt:diff."""
53
54=== modified file 'lib/lp/soyuz/browser/archive.py'
55--- lib/lp/soyuz/browser/archive.py 2010-12-06 15:24:03 +0000
56+++ lib/lp/soyuz/browser/archive.py 2010-12-20 05:52:31 +0000
57@@ -916,8 +916,9 @@
58 else:
59 description = ''
60
61- if not (self.context.owner.is_probationary and self.context.is_ppa):
62- description = formatter(description).text_to_html()
63+ if self.context.is_ppa:
64+ description = formatter(description).text_to_html(
65+ linkify_text=(not self.context.owner.is_probationary))
66
67 return TextAreaEditorWidget(
68 self.context,
69
70=== modified file 'lib/lp/soyuz/browser/tests/archive-views.txt'
71--- lib/lp/soyuz/browser/tests/archive-views.txt 2010-10-09 16:36:22 +0000
72+++ lib/lp/soyuz/browser/tests/archive-views.txt 2010-12-20 05:52:31 +0000
73@@ -449,7 +449,17 @@
74 True
75
76 >>> print view.archive_description_html.value
77- http://example.dom/
78+ <p>http://example.dom/</p>
79+
80+The description is HTML escaped, and not linkified even when it contains HTML
81+tags.
82+
83+ >>> login('admin@canonical.com')
84+ >>> cprov.archive.description = (
85+ ... '<a href="http://example.com/">http://example.com/</a>')
86+ >>> login(ANONYMOUS)
87+ >>> print view.archive_description_html.value
88+ <p>&lt;a href="http://example.com/"&gt;http://example.com/&lt;/a&gt;</p>
89
90 The PPA description is linked when the user has made a contribution.
91