[#6667] Fix bug in comment update parsing
- Instead of iterating through all text nodes, which can break if
there are an odd number, find the labels (<b> tags) and their
sibling nodes (descriptions) explicitly
Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index d4eb83d..1a2c5c1 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -234,12 +234,9 @@
def _get_updates(self, tag):
_updates = tag.find('div', 'updates')
- if _updates:
- _strings = _updates.findAll(text=True)
- updates = (s.strip() for s in _strings if s.strip())
- self.updates = {field: updates.next() for field in updates}
- else:
- self.updates = {}
+ self.updates = {
+ b.text: b.nextSibling.strip()
+ for b in _updates.findAll('b')} if _updates else {}
@property
def annotated_text(self):
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 32b3049..4eff44f 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -284,3 +284,49 @@
tag.get.return_value = '/p/project'
link = google.UserLink(tag)
self.assertEqual(str(link), '[name](http://code.google.com/p/project)')
+
+
+class TestComment(TestCase):
+ html = """
+ <div class="cursor_off vt issuecomment" id="hc2">
+ <div style="float:right; margin-right:.3em; text-align:right">
+ <span class="date" title="Tue Jun 25 03:20:09 2013">
+ Jun 25, 2013
+ </span>
+ </div>
+ <span class="author">
+ <span class="role_label">Project Member</span>
+ <a name="c2" href="/p/pychess/issues/detail?id=267#c2">#2</a>
+ <a class="userlink" href="/u/gbtami/">gbtami</a></span>
+ <pre><i>(No comment was entered for this change.)</i>
+ </pre>
+ <div class="updates">
+ <div class="round4"></div>
+ <div class="round2"></div>
+ <div class="round1"></div>
+ <div class="box-inner">
+ <b>Summary:</b>
+ Make PyChess keyboard accessible
+ <span class="oldvalue">
+ (was: Make PyChess keyboard accecible)
+ </span>
+ <br>
+ <b>Status:</b>
+ Accepted
+ <br>
+ </div>
+ <div class="round1"></div>
+ <div class="round2"></div>
+ <div class="round4"></div>
+ </div>
+ </div>
+ """
+
+ def test_init(self):
+ from BeautifulSoup import BeautifulSoup
+ html = BeautifulSoup(self.html)
+ comment = google.Comment(html.find('div', 'issuecomment'))
+ self.assertEqual(comment.updates, {
+ u'Summary:': u'Make PyChess keyboard accessible',
+ u'Status:': u'Accepted',
+ })