jenkins-bot has submitted this change and it was merged.

Change subject: does_text_contain_section should match preleading ":" in 
textlinks
......................................................................


does_text_contain_section should match preleading ":" in textlinks

When a section header contains a text link with preleading colon,
it should match it too:

== [[This is a section header]] ==

== [[:This is also a valid section header]] ==

Additional comments see doc string.

Change-Id: Ie52c3956b4d82bb71c2113cbff476c3dec61fa0c
---
M pywikibot/textlib.py
1 file changed, 20 insertions(+), 3 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 725d676..fdcda92 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -7,7 +7,7 @@
 
 """
 #
-# (C) Pywikibot team, 2008-2013
+# (C) Pywikibot team, 2008-2014
 #
 # Distributed under the terms of the MIT license.
 #
@@ -1104,8 +1104,25 @@
 #----------------------------------
 
 def does_text_contain_section(pagetext, section):
-    section = re.sub(r'\\[ _]', '[ _]', re.escape(section))
-    """Determines whether the page text contains the given section title."""
+    """
+    Determines whether the page text contains the given section title.
+
+    @param pagetext: The wikitext of a page
+    @type text: unicode or string
+    @param section: a section of a page including wikitext markups
+    @type section: unicode or string
+
+    Note: It does not care whether a section string may contain spaces or
+          underlines. Both will match.
+          If a section parameter contains a internal link, it will match the
+          section with or without a preleading colon which is required for a
+          text link e.g. for categories and files.
+
+    """
+    # match preleading colon for text links
+    section = re.sub(r'\\\[\\\[(\\\:)?', '\[\[\:?', re.escape(section))
+    # match underscores and white spaces
+    section = re.sub(r'\\[ _]', '[ _]', section)
     m = re.search("=+[ ']*%s[ ']*=+" % section, pagetext)
     return bool(m)
 

-- 
To view, visit https://gerrit.wikimedia.org/r/114987
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie52c3956b4d82bb71c2113cbff476c3dec61fa0c
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to