]> granicus.if.org Git - python/commitdiff
Merged revisions 71537 via svnmerge from
authorGeorg Brandl <georg@python.org>
Sun, 12 Apr 2009 17:26:19 +0000 (17:26 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 12 Apr 2009 17:26:19 +0000 (17:26 +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 b6af6f9bab916a4eb24de35dcddb7f6f60ccdb08..aa4f196fa44ec206de8d62a7655eb035c284c0d5 100644 (file)
@@ -614,7 +614,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:
@@ -661,9 +660,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 a8b5d7c389ad4ed48a5db1bda3668173c8b2199b..173f40fa066f182a728a73c7dc3b77ba2840cb71 100644 (file)
@@ -434,6 +434,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 dc88679d26bb0eb685217d71b4a040d4c897c7d3..35d4122a94835ac6bf15ef79974f7205b6fe8df2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5741: don't disallow "%%" (which is an escape for "%") when setting
+  a value in SafeConfigParser.
+
 - Issue #5731: Distutils bdist_wininst no longer worked on non-Windows 
   platforms. Initial patch by Paul Moore.