mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
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>
This commit is contained in:
parent
1e4a4344af
commit
25a7ddf2ef
4 changed files with 58 additions and 1 deletions
|
@ -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"})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue