Merge lp:~gmb/trac-launchpad-migrator/fix-render_text-bug-456182 into lp:trac-launchpad-migrator

Proposed by Graham Binns
Status: Merged
Approved by: Gavin Panella
Approved revision: 19
Merged at revision: not available
Proposed branch: lp:~gmb/trac-launchpad-migrator/fix-render_text-bug-456182
Merge into: lp:trac-launchpad-migrator
Diff against target: 63 lines
2 files modified
migrate.py (+4/-8)
tests.py (+24/-1)
To merge this branch: bzr merge lp:~gmb/trac-launchpad-migrator/fix-render_text-bug-456182
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Canonical Launchpad Engineering code Pending
Review via email: mp+13630@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

This branch fixes bug 456182, which makes the migrator mangle bug descriptions with more than one Trac wiki markup block in them.

The simple fix was to simplify the code that removed the block markup (because multiline regexes are asking for pain).

Revision history for this message
Gavin Panella (allenap) wrote :

This looks good, though I'm inclined to think we should just leave the description alone entirely.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'migrate.py'
2--- migrate.py 2009-10-19 13:50:08 +0000
3+++ migrate.py 2009-10-20 10:40:23 +0000
4@@ -290,15 +290,11 @@
5 # handle trac {{{ }}} formatting (incl. ReST).
6 text = ''.join([_rstrip(line).expandtabs() + "\n"
7 for line in text.splitlines()])
8- for regex in (RST_RE, PRE_RE):
9- rg = re.compile(regex,
10- re.IGNORECASE|re.DOTALL|re.MULTILINE)
11- m = rg.search(text)
12- if m:
13- text = m.group(1)
14- break
15
16- return text
17+ # Simply remove the {{{s and }}}s from the text. We don't want to
18+ # care too much about blocks right now, so we just remove them.
19+ block_re = re.compile('(\{\{\{|\}\}\})\r?\n')
20+ return block_re.sub('', text)
21
22
23 def ensure_valid_username(username):
24
25=== modified file 'tests.py'
26--- tests.py 2009-10-19 13:49:32 +0000
27+++ tests.py 2009-10-20 10:40:23 +0000
28@@ -18,7 +18,8 @@
29 import re
30 import unittest
31
32-from migrate import ensure_valid_username, extract_person_email
33+from migrate import (
34+ ensure_valid_username, extract_person_email, render_text)
35
36
37 class ExtractPersonEmailTestCase(unittest.TestCase):
38@@ -180,3 +181,25 @@
39 re.match('\s+', returned_name) is None,
40 "Returned name '%s' shouldn't contain whitespace" %
41 returned_name)
42+
43+
44+class RenderTextTestCase(unittest.TestCase):
45+ """Tests for the render_text function."""
46+
47+ def test_render_text_removes_blocks(self):
48+ # render_text will strip out {{{s and }}}s from text.
49+ text = (
50+ "This is a description\n"
51+ "{{{\n"
52+ "Which has some block text\n"
53+ "}}}\n")
54+
55+ expected_text = (
56+ "This is a description\n"
57+ "Which has some block text\n")
58+
59+ rendered_text = render_text(text)
60+ self.assertEqual(
61+ rendered_text, expected_text,
62+ "render_text returned '%s', expected '%s'" %
63+ (rendered_text, expected_text))

Subscribers

People subscribed via source and target branches

to all changes: