← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/text_to_html-no-linkify into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


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.
-- 
https://code.launchpad.net/~stevenk/launchpad/text_to_html-no-linkify/+merge/44192
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/text_to_html-no-linkify into lp:launchpad.
=== modified file 'lib/lp/app/browser/stringformatter.py'
--- lib/lp/app/browser/stringformatter.py	2010-12-17 18:11:02 +0000
+++ lib/lp/app/browser/stringformatter.py	2010-12-20 05:51:58 +0000
@@ -479,7 +479,7 @@
     # re-attaches parens if we do want them to be part of the url.
     _re_url_trailers = re.compile(r'([,.?:);>]+)$')
 
-    def text_to_html(self):
+    def text_to_html(self, linkify_text=True):
         """Quote text according to DisplayingParagraphsOfText."""
         # This is based on the algorithm in the
         # DisplayingParagraphsOfText spec, but is a little more
@@ -512,9 +512,10 @@
 
         text = ''.join(output)
 
-        # Linkify the text.
-        text = re_substitute(self._re_linkify, self._linkify_substitution,
-                             break_long_words, text)
+        # Linkify the text, if allowed.
+        if linkify_text is True:
+            text = re_substitute(self._re_linkify, self._linkify_substitution,
+                break_long_words, text)
 
         return text
 

=== modified file 'lib/lp/app/browser/tests/test_stringformatter.py'
--- lib/lp/app/browser/tests/test_stringformatter.py	2010-12-17 16:13:21 +0000
+++ lib/lp/app/browser/tests/test_stringformatter.py	2010-12-20 05:51:58 +0000
@@ -209,6 +209,21 @@
             'data:text/<wbr></wbr>plain,test</a></p>')
         self.assertEqual(expected_html, html)
 
+    def test_no_link_with_linkify_text_false(self):
+        test_string = "This doesn't become a link: http://www.example.com/";
+        html = FormattersAPI(test_string).text_to_html(linkify_text=False)
+        expected_html = (
+            "<p>This doesn't become a link: http://www.example.com/</p>")
+        self.assertEqual(expected_html, html)
+
+    def test_no_link_html_code_with_linkify_text_false(self):
+        test_string = '<a href="http://example.com/";>http://example.com/</a>'
+        html = FormattersAPI(test_string).text_to_html(linkify_text=False)
+        expected_html = (
+            '<p>&lt;a href="http://example.com/"&gt;'
+            'http://example.com/&lt;/a&gt;</p>')
+        self.assertEqual(expected_html, html)
+
 
 class TestDiffFormatter(TestCase):
     """Test the string formatter fmt:diff."""

=== modified file 'lib/lp/soyuz/browser/archive.py'
--- lib/lp/soyuz/browser/archive.py	2010-12-06 15:24:03 +0000
+++ lib/lp/soyuz/browser/archive.py	2010-12-20 05:51:58 +0000
@@ -916,8 +916,9 @@
         else:
             description = ''
 
-        if not (self.context.owner.is_probationary and self.context.is_ppa):
-            description = formatter(description).text_to_html()
+        if self.context.is_ppa:
+            description = formatter(description).text_to_html(
+                linkify_text=(not self.context.owner.is_probationary))
 
         return TextAreaEditorWidget(
             self.context,

=== modified file 'lib/lp/soyuz/browser/tests/archive-views.txt'
--- lib/lp/soyuz/browser/tests/archive-views.txt	2010-10-09 16:36:22 +0000
+++ lib/lp/soyuz/browser/tests/archive-views.txt	2010-12-20 05:51:58 +0000
@@ -449,7 +449,17 @@
     True
 
     >>> print view.archive_description_html.value
-    http://example.dom/
+    <p>http://example.dom/</p>
+
+The description is HTML escaped, and not linkified even when it contains HTML
+tags.
+
+    >>> login('admin@xxxxxxxxxxxxx')
+    >>> cprov.archive.description = (
+    ...     '<a href="http://example.com/";>http://example.com/</a>')
+    >>> login(ANONYMOUS)
+    >>> print view.archive_description_html.value
+    <p>&lt;a href="http://example.com/"&gt;http://example.com/&lt;/a&gt;</p>
 
 The PPA description is linked when the user has made a contribution.