diff options
author | Jacob Austin Lincoln <99031153+lincolnj1@users.noreply.github.com> | 2025-02-23 16:06:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-23 16:06:33 (GMT) |
commit | 25a7ddf2efeaf77bcf94dbfca28ba3a6fe9ab57e (patch) | |
tree | 1e4c59ae665d4f14e4e714ede90375a79a30383c /Lib/test/test_configparser.py | |
parent | 1e4a4344af4f5fdc7157b195c7d333d088540035 (diff) | |
download | cpython-25a7ddf2efeaf77bcf94dbfca28ba3a6fe9ab57e.zip cpython-25a7ddf2efeaf77bcf94dbfca28ba3a6fe9ab57e.tar.gz cpython-25a7ddf2efeaf77bcf94dbfca28ba3a6fe9ab57e.tar.bz2 |
gh-65697: Prevent configparser from writing keys it cannot properly read (#129270)
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
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 c2c82eb..1313ec2 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"}) |