]> granicus.if.org Git - python/commitdiff
Merged revisions 71537 via svnmerge from
authorGeorg Brandl <georg@python.org>
Mon, 27 Apr 2009 16:42:58 +0000 (16:42 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 27 Apr 2009 16:42:58 +0000 (16:42 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71537 | georg.brandl | 2009-04-12 19:24:11 +0200 (So, 12 Apr 2009) | 1 line

  #5741: dont disallow double percent signs in SafeConfigParser.set() keys.
........

Lib/configparser.py
Lib/test/test_cfgparser.py
Misc/NEWS

index 7510a6ef614385d4465356fdfd2532750da7de57..4fc9a8d4e492dfee3b7b6de82c3f32e959d535a8 100644 (file)
@@ -620,7 +620,6 @@ class SafeConfigParser(ConfigParser):
         return ''.join(L)
 
     _interpvar_re = re.compile(r"%\(([^)]+)\)s")
-    _badpercent_re = re.compile(r"%[^%]|%$")
 
     def _interpolate_some(self, option, accum, rest, section, map, depth):
         if depth > MAX_INTERPOLATION_DEPTH:
@@ -667,9 +666,10 @@ class SafeConfigParser(ConfigParser):
         # check for bad percent signs:
         # first, replace all "good" interpolations
         tmp_value = self._interpvar_re.sub('', value)
+        tmp_value = tmp_value.replace('%%', '')
         # then, check if there's a lone percent sign left
-        m = self._badpercent_re.search(tmp_value)
-        if m:
+        percent_index = tmp_value.find('%')
+        if percent_index != -1:
             raise ValueError("invalid interpolation syntax in %r at "
-                             "position %d" % (value, m.start()))
+                             "position %d" % (value, percent_index))
         ConfigParser.set(self, section, option, value)
index a8418ca5cc6c731c2a2c1b0d6bf10d17488ffbfa..12fd00cbf177bd8eb4475feef318c2298b73d480 100644 (file)
@@ -424,6 +424,10 @@ class SafeConfigParserTestCase(ConfigParserTestCase):
 
         self.assertEqual(cf.get('sect', "option1"), "foo")
 
+        # bug #5741: double percents are *not* malformed
+        cf.set("sect", "option2", "foo%%bar")
+        self.assertEqual(cf.get("sect", "option2"), "foo%bar")
+
     def test_set_nonstring_types(self):
         cf = self.fromstring("[sect]\n"
                              "option1=foo\n")
index 217276f11b06d5cdbf90b23a454c3a49f756fff9..44fbc4736871dfe323638ba43c4f162e7b62b0a6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -467,6 +467,9 @@ Library
 
 - Issue #5607: fixed Distutils test_get_platform for Mac OS X fat binaries.
 
+- Issue #5741: don't disallow "%%" (which is an escape for "%") when setting
+  a value in SafeConfigParser.
+
 - Issue #5732: added a new command in Distutils: check.
 
 - Issue #5731: Distutils bdist_wininst no longer worked on non-Windows