[damned-lies] Prevent bugzilla_linkify to catch encoded entities (#669240)



commit b157e003a14c5bbabb7ae4f37d24a309b757ff6e
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Feb 2 14:49:11 2012 +0100

    Prevent bugzilla_linkify to catch encoded entities (#669240)

 stats/templatetags/stats_extras.py |    3 ++-
 stats/tests/__init__.py            |   12 ++++++++++++
 vertimus/admin.py                  |    2 +-
 3 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index 5ffee1c..a7480d3 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -163,7 +163,8 @@ def as_tr(field):
 def bugzilla_linkify(text):
     """Searches within the given text if a text matching a bugzilla bug reference
     is found and transforms it to a link to that bug"""
-    bug_id = re.compile('(?P<id>#[0-9]+)')
+    # Should not catch encoded entities (&#39;)
+    bug_id = re.compile('(?<!&)(?P<id>#[0-9]+)')
     repl = u'<a rel="nofollow" href="https://bugzilla.gnome.org/show_bug.cgi?id=\g<id>">\g<id></a>'
 
     result = bug_id.sub(repl, text)
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index a97ce88..53932c9 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -284,3 +284,15 @@ class FigureTests(TestCase):
         errs = check_identical_figures(doc_stat.get_figures(), os.path.join(branch.co_path(), 'help'), 'fr')
         self.assertEqual(len(errs), 1)
         self.assertTrue(errs[0][1].startswith("Figures should not be copied"))
+
+class OtherTests(TestCase):
+    def test_bugzilla_linkify(self):
+        from stats.templatetags.stats_extras import bugzilla_linkify
+        self.assertEqual(bugzilla_linkify(u"Sample normal text should not be altered."),
+            u"Sample normal text should not be altered.")
+        self.assertEqual(bugzilla_linkify(u"Bugzilla bug numbers like #669240 should be linkified"),
+            u'Bugzilla bug numbers like <a rel="nofollow" href="https://bugzilla.gnome.org/show_bug.cgi?id=669240";>#669240</a> should be linkified')
+        self.assertEqual(bugzilla_linkify(u"#669240 start or finish #669240"),
+            u'<a rel="nofollow" href="https://bugzilla.gnome.org/show_bug.cgi?id=669240";>#669240</a> start or finish <a rel="nofollow" href="https://bugzilla.gnome.org/show_bug.cgi?id=669240";>#669240</a>')
+        self.assertEqual(bugzilla_linkify(u"Test with encoded entities (rock&#39;n roll) should not."),
+            u"Test with encoded entities (rock&#39;n roll) should not.")
diff --git a/vertimus/admin.py b/vertimus/admin.py
index e4af7aa..46ebe48 100644
--- a/vertimus/admin.py
+++ b/vertimus/admin.py
@@ -8,7 +8,7 @@ class StateAdmin(admin.ModelAdmin):
     search_fields = ('branch__module__name',)
 
 class ActionAdmin(admin.ModelAdmin):
-    list_display = ('__unicode__', 'state_db')
+    list_display = ('__unicode__', 'state_db', 'merged_file')
     raw_id_fields = ('state_db', 'person')
     search_fields = ('comment',)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]