fix regex matching on revisions with deleted text or comments
RegexPair.matchmake crashed with a TypeError when a capture-group pattern was applied to a revision whose text or comment was deleted or suppressed (content is None). Guard both matching paths against None, and make the no-capture-group path emit a None column for such revisions instead of omitting the key entirely. This carries forward the fix Kaylea Champion and Mako Hill made on the mako_changes-20230429 branch (7e6cd5b), which predated the rewrite. Adds a unit test for matchmake(None) and an end-to-end test against the ikwiki dump, which contains revisions with deleted text and comments. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commitdbcae5c64e)
This commit is contained in:
@@ -463,7 +463,8 @@ class RegexPair(object):
|
||||
# if there are named capture groups in the regex
|
||||
if self.has_groups:
|
||||
# if there are matches of some sort in this revision content, fill the lists for each cap_group
|
||||
if self.pattern.search(content) is not None:
|
||||
# content can be None when the text or comment was deleted/suppressed
|
||||
if content is not None and self.pattern.search(content) is not None:
|
||||
m = self.pattern.finditer(content)
|
||||
matchobjects = list(m)
|
||||
|
||||
@@ -491,12 +492,11 @@ class RegexPair(object):
|
||||
# there are no capture groups, we just search for all the matches of the regex
|
||||
else:
|
||||
# given that there are matches to be made
|
||||
if type(content) in (str, bytes):
|
||||
if self.pattern.search(content) is not None:
|
||||
m = self.pattern.findall(content)
|
||||
temp_dict[self.label] = ", ".join(m)
|
||||
else:
|
||||
temp_dict[self.label] = None
|
||||
if content is not None and self.pattern.search(content) is not None:
|
||||
m = self.pattern.findall(content)
|
||||
temp_dict[self.label] = ", ".join(m)
|
||||
else:
|
||||
temp_dict[self.label] = None
|
||||
|
||||
return temp_dict
|
||||
|
||||
|
||||
Reference in New Issue
Block a user