diff options
Diffstat (limited to 'Lib/test/test_configparser.py')
-rw-r--r-- | Lib/test/test_configparser.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index c2c82ebe6a8..1313ec2b9e8 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -2192,6 +2192,30 @@ class SectionlessTestCase(unittest.TestCase): self.assertEqual('2', cfg[configparser.UNNAMED_SECTION]['b']) +class InvalidInputTestCase(unittest.TestCase): + """Tests for issue #65697, where configparser will write configs + it parses back differently. Ex: keys containing delimiters or + matching the section pattern""" + + def test_delimiter_in_key(self): + cfg = configparser.ConfigParser(delimiters=('=')) + cfg.add_section('section1') + cfg.set('section1', 'a=b', 'c') + output = io.StringIO() + with self.assertRaises(configparser.InvalidWriteError): + cfg.write(output) + output.close() + + def test_section_bracket_in_key(self): + cfg = configparser.ConfigParser() + cfg.add_section('section1') + cfg.set('section1', '[this parses back as a section]', 'foo') + output = io.StringIO() + with self.assertRaises(configparser.InvalidWriteError): + cfg.write(output) + output.close() + + class MiscTestCase(unittest.TestCase): def test__all__(self): support.check__all__(self, configparser, not_exported={"Error"}) |