[Python-checkins] r71537 - in python/trunk: Lib/ConfigParser.py Lib/test/test_cfgparser.py Misc/NEWS
georg.brandl
python-checkins at python.org
Sun Apr 12 19:24:12 CEST 2009
Author: georg.brandl
Date: Sun Apr 12 19:24:11 2009
New Revision: 71537
Log:
#5741: dont disallow double percent signs in SafeConfigParser.set() keys.
Modified:
python/trunk/Lib/ConfigParser.py
python/trunk/Lib/test/test_cfgparser.py
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/ConfigParser.py
==============================================================================
--- python/trunk/Lib/ConfigParser.py (original)
+++ python/trunk/Lib/ConfigParser.py Sun Apr 12 19:24:11 2009
@@ -620,7 +620,6 @@
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 @@
# 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)
Modified: python/trunk/Lib/test/test_cfgparser.py
==============================================================================
--- python/trunk/Lib/test/test_cfgparser.py (original)
+++ python/trunk/Lib/test/test_cfgparser.py Sun Apr 12 19:24:11 2009
@@ -434,6 +434,10 @@
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")
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sun Apr 12 19:24:11 2009
@@ -221,6 +221,9 @@
Library
-------
+- 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
More information about the Python-checkins
mailing list