jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/318884 )
Change subject: textlib.py: Limit catastrophic backtracking in FILE_LINK_REGEX ......................................................................
textlib.py: Limit catastrophic backtracking in FILE_LINK_REGEX
Make use of the fact that wikilinks cannot contain other wikilinks.
This breaks the test that asserts wikilinks inside files can contain other wikilinks. Remove that test. This should be OK because MediaWiki does not allow such syntax errors, too, i.e. `[[File:example.jpg|[[foo]] [[bar [[invalid]] ]].x]]` won't be rendered as an image by MediaWiki.
Bug: T148959 Change-Id: Id300a386a1760cca5717ac907108e8f34d51e222 --- M pywikibot/textlib.py M tests/textlib_tests.py 2 files changed, 1 insertion(+), 9 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, but someone else must approve jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index fc7c4b1..ad14880 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -110,8 +110,7 @@ FILE_LINK_REGEX = r""" [[\s*(?:%s)\s*:[^|]*?\s* (| - ( [[ [^[]*? [[ [^]]*? ]] [^]]*? ]] # capture invalid syntax - | ( [[ .*? ]] )? [^[]*? + ( ( [[ .*? ]] )? [^[]*? | [ [^]]*? ] )* )? diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 103d848..496e1b5 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -1285,13 +1285,6 @@ 'x', 'y', ['file'], site=self.site), '[[File:a|[[foo]] [[bar [invalid ]].x]][[y]]')
- # Even handle balanced [[ ]] inside the wikilink. - self.assertEqual( - textlib.replaceExcept( - '[[File:a|[[foo]] [[bar [[invalid]] ]].x]][[x]]', - 'x', 'y', ['file'], site=self.site), - '[[File:a|[[foo]] [[bar [[invalid]] ]].x]][[y]]') - @unittest.expectedFailure def test_replace_tag_file_failure(self): """Test showing limits of the file link regex."""
pywikibot-commits@lists.wikimedia.org