mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Implement a safer and more predictable interpolation approach.
Closes SF bug #511737.
This commit is contained in:
parent
98e3b29b59
commit
0eebd5cef9
3 changed files with 74 additions and 1 deletions
|
@ -289,10 +289,25 @@ class RawConfigParserTestCase(TestCaseBase):
|
|||
('name', 'value')])
|
||||
|
||||
|
||||
class SafeConfigParserTestCase(ConfigParserTestCase):
|
||||
config_class = ConfigParser.SafeConfigParser
|
||||
|
||||
def test_safe_interpolation(self):
|
||||
# See http://www.python.org/sf/511737
|
||||
cf = self.fromstring("[section]\n"
|
||||
"option1=xxx\n"
|
||||
"option2=%(option1)s/xxx\n"
|
||||
"ok=%(option1)s/%%s\n"
|
||||
"not_ok=%(option2)s/%%s")
|
||||
self.assertEqual(cf.get("section", "ok"), "xxx/%s")
|
||||
self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s")
|
||||
|
||||
|
||||
def test_main():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTests([unittest.makeSuite(ConfigParserTestCase),
|
||||
unittest.makeSuite(RawConfigParserTestCase)])
|
||||
unittest.makeSuite(RawConfigParserTestCase),
|
||||
unittest.makeSuite(SafeConfigParserTestCase)])
|
||||
test_support.run_suite(suite)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue