Merge lp:~jcsackett/launchpad/better-bug-linking-531889 into lp:launchpad

Proposed by j.c.sackett on 2010-12-17
Status: Merged
Approved by: j.c.sackett on 2010-12-20
Approved revision: no longer in the source branch.
Merged at revision: 12130
Proposed branch: lp:~jcsackett/launchpad/better-bug-linking-531889
Merge into: lp:launchpad
Diff against target: 93 lines (+41/-5)
3 files modified
lib/lp/app/browser/stringformatter.py (+4/-2)
lib/lp/app/browser/tests/test_stringformatter.py (+35/-1)
lib/lp/app/doc/displaying-paragraphs-of-text.txt (+2/-2)
To merge this branch: bzr merge lp:~jcsackett/launchpad/better-bug-linking-531889
Reviewer Review Type Date Requested Status
Leonard Richardson (community) 2010-12-17 Approve on 2010-12-20
Review via email: mp+44098@code.launchpad.net

Commit Message

[r=leonardr][ui=none][bug=531889] Fixes linking conditions for bug references in bug comments.

Description of the Change

Summary
=======

Bugs are automatically linked based on the appearance of certain strings (bug no <somenumber>, bug #<somenumber, &c). However, some of these combinations are linked even when they're the result of apparent typos. This branch updates the regex to avoid matching on these patterns.

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

The bug pattern group in the _re_linkify regex is slightly modified to deal with an appropriate amount of spacing and not match the the phrase "bug number" at the end of a sentence.

Tests
=====

bin/test -t LinkifyingBugs

Lint
====

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/app/browser/stringformatter.py
  lib/lp/app/browser/tests/test_stringformatter.py

./lib/lp/app/browser/stringformatter.py
     408: E501 line too long (88 characters)
     412: E501 line too long (86 characters)
     408: Line exceeds 78 characters.
     412: Line exceeds 78 characters.

E501s are from long sections of the primary linking regex, which may be even harder to read if those lines are wrapped.

To post a comment you must log in.
Leonard Richardson (leonardr) wrote :

You left the ? in the "number?" part of your regular expressions, which will make "bug numbe 10" match when it shouldn't. Take that out and it looks good.

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-20 15:37:02 +0000
3+++ lib/lp/app/browser/stringformatter.py 2010-12-21 16:19:53 +0000
4@@ -457,11 +457,13 @@
5 )
6 ) |
7 (?P<bug>
8- \bbug(?:[\s=-]|<br\s*/>)*(?:\#|report|number\.?|num\.?|no\.?)?(?:[\s=-]|<br\s*/>)*
9+ \bbug(?:[\s=-]|<br\s*/>)*
10+ (?:(?:(?:\#|report|number|num\.?|no\.?)?(?:[\s=-]|<br\s*/>)+)|
11+ (?:(?:\s\#)?(?:[\s=-]|<br\s*/>)*))
12 0*(?P<bugnum>\d+)
13 ) |
14 (?P<faq>
15- \bfaq(?:[\s=-]|<br\s*/>)*(?:\#|item|number\.?|num\.?|no\.?)?(?:[\s=-]|<br\s*/>)*
16+ \bfaq(?:[\s=-]|<br\s*/>)*(?:\#|item|number?|num\.?|no\.?)?(?:[\s=-]|<br\s*/>)*
17 0*(?P<faqnum>\d+)
18 ) |
19 (?P<oops>
20
21=== modified file 'lib/lp/app/browser/tests/test_stringformatter.py'
22--- lib/lp/app/browser/tests/test_stringformatter.py 2010-12-20 15:13:30 +0000
23+++ lib/lp/app/browser/tests/test_stringformatter.py 2010-12-21 16:19:53 +0000
24@@ -107,6 +107,40 @@
25 <tag>1234567890123456</tag>
26 """
27
28+class TestLinkifyingBugs(TestCase):
29+
30+ def test_regular_bug_case_works(self):
31+ test_strings = [
32+ "bug 34434",
33+ "bugnumber 34434",
34+ "bug number 34434",
35+ ]
36+ expected_html = [
37+ '<p><a href="/bugs/34434">bug 34434</a></p>',
38+ '<p><a href="/bugs/34434">bugnumber 34434</a></p>',
39+ '<p><a href="/bugs/34434">bug number 34434</a></p>',
40+ ]
41+ self.assertEqual(
42+ expected_html,
43+ [FormattersAPI(text).text_to_html() for text in test_strings])
44+
45+ def test_things_do_not_link_if_they_should_not(self):
46+ test_strings = [
47+ "bugnumber.4",
48+ "bug number.4",
49+ "bugno.4",
50+ "bug no.4",
51+ ]
52+ expected_html = [
53+ "<p>bugnumber.4</p>",
54+ "<p>bug number.4</p>",
55+ "<p>bugno.4</p>",
56+ "<p>bug no.4</p>",
57+ ]
58+ self.assertEqual(
59+ expected_html,
60+ [FormattersAPI(text).text_to_html() for text in test_strings])
61+
62
63 class TestLinkifyingProtocols(TestCase):
64
65@@ -271,7 +305,7 @@
66 html = FormattersAPI(diff).format_diff()
67 line_numbers = find_tags_by_class(html, 'line-no')
68 self.assertEqual(
69- ['1','2','3','4','5','6','7','8','9', '10', '11'],
70+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
71 [tag.renderContents() for tag in line_numbers])
72 text = find_tags_by_class(html, 'text')
73 self.assertEqual(
74
75=== modified file 'lib/lp/app/doc/displaying-paragraphs-of-text.txt'
76--- lib/lp/app/doc/displaying-paragraphs-of-text.txt 2010-10-19 03:28:24 +0000
77+++ lib/lp/app/doc/displaying-paragraphs-of-text.txt 2010-12-21 16:19:53 +0000
78@@ -229,13 +229,13 @@
79 <a href="/bugs/123">bug 123</a><br />
80 <a href="/bugs/123">bug #123</a><br />
81 <a href="/bugs/123">bug number 123</a><br />
82- <a href="/bugs/123">bug number. 123</a><br />
83+ bug number. 123<br />
84 <a href="/bugs/123">bug num 123</a><br />
85 <a href="/bugs/123">bug num. 123</a><br />
86 <a href="/bugs/123">bug no 123</a><br />
87 <a href="/bugs/123">bug report 123</a><br />
88 <a href="/bugs/123">bug no. 123</a><br />
89- <a href="/bugs/123">bug#123</a><br />
90+ bug#123<br />
91 <a href="/bugs/123">bug-123</a><br />
92 <a href="/bugs/123">bug-report-123</a><br />
93 <a href="/bugs/123">bug=123</a><br />