Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gensim/corpora/wikicorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

RE_P0 = re.compile(r'<!--.*?-->', re.DOTALL | re.UNICODE)
"""Comments."""
RE_P1 = re.compile(r'<ref([> ].*?)(</ref>|/>)', re.DOTALL | re.UNICODE)
RE_P1 = re.compile(r'<ref(\s[^>]*?)?/>|<ref(\s[^>]*?)?>.*?</ref>', re.DOTALL | re.UNICODE)
"""Footnotes."""
RE_P2 = re.compile(r'(\n\[\[[a-z][a-z][\w-]*:[^:\]]+\]\])+$', re.UNICODE)
"""Links to languages."""
Expand Down
11 changes: 11 additions & 0 deletions gensim/test/test_corpora.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,17 @@ def test_default_preprocessing(self):
first_text = next(corpus.get_texts())
self.assertEqual(expected, first_text)

def test_filter_wiki_ref_with_nested_self_closing_tag(self):
# Regression test for #3520: a <ref>...</ref> footnote that contains a nested
# self-closing tag (e.g. <nowiki/> or <br/>) must be removed entirely, not
# truncated at the nested tag's "/>", which used to leak the rest of the footnote.
text = "total<ref>note<nowiki/>https://example.com/x</ref>end"
self.assertEqual(wikicorpus.filter_wiki(text), "totalend")

# Self-closing and plain paired refs are still removed.
self.assertEqual(wikicorpus.filter_wiki('a<ref name="r"/>b'), "ab")
self.assertEqual(wikicorpus.filter_wiki("a<ref>note</ref>b"), "ab")

def test_len(self):
# When there is no min_token limit all 9 articles must be registered.
corpus = self.corpus_class(self.fname, article_min_tokens=0)
Expand Down
Loading