Revision: 6002
Author: nicdumz
Date: 2008-10-20 03:11:06 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
(bug 2169485) image.py bug : fixing re escaping issues
Modified Paths:
--------------
trunk/pywikipedia/image.py
Modified: trunk/pywikipedia/image.py
===================================================================
--- trunk/pywikipedia/image.py 2008-10-20 02:46:48 UTC (rev 6001)
+++ trunk/pywikipedia/image.py 2008-10-20 03:11:06 UTC (rev 6002)
@@ -119,12 +119,13 @@
site = wikipedia.getSite()
if not site.nocapitalize:
- old = '[' + self.oldImage[0].upper() + self.oldImage[0].lower() + ']' + self.oldImage[1:]
+ case = re.escape( self.oldImage[0].upper() + self.oldImage[0].lower() )
+ escaped = '[' + case + ']' + re.escape(self.oldImage[1:])
else:
- old = self.oldImage
+ escaped = re.escape( self.oldImage )
- old = re.sub('[_ ]', '[_ ]', old)
- escaped = re.escape(old)
+ # Be careful, spaces and _ have been converted to '\ ' and '\_'
+ escaped = re.sub('\\\\[_ ]', '[_ ]', escaped)
if not self.loose or not self.newImage:
ImageRegex = re.compile(r'\[\[ *(?:' + '|'.join(site.namespace(6, all = True)) + ')\s*:\s*' + escaped + ' *(?P<parameters>\|[^\n]+|) *\]\]')
else: