Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ class RawConfigParser(MutableMapping):
_OPT_TMPL = r"""
(?P<option> # very permissive!
(?:(?!{delim})\S)* # non-delimiter non-whitespace
(?:\s+(?:(?!{delim})\S)+)*) # optionally more words
(?:(?:(?!{delim})\s)+(?:(?!{delim})\S)+)*) # optionally more words
\s*(?P<vi>{delim})\s* # any number of space/tab,
# followed by any of the
# allowed delimiters,
Expand All @@ -628,7 +628,7 @@ class RawConfigParser(MutableMapping):
_OPT_NV_TMPL = r"""
(?P<option> # very permissive!
(?:(?!{delim})\S)* # non-delimiter non-whitespace
(?:\s+(?:(?!{delim})\S)+)*) # optionally more words
(?:(?:(?!{delim})\s)+(?:(?!{delim})\S)+)*) # optionally more words
\s*(?: # any number of space/tab,
(?P<vi>{delim})\s* # optionally followed by
# any of the allowed
Expand Down
14 changes: 11 additions & 3 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CfgParserTestCaseClass:
default_section = configparser.DEFAULTSECT
interpolation = configparser._UNSET

def newconfig(self, defaults=None):
def newconfig(self, defaults=None, **kwargs):
arguments = dict(
defaults=defaults,
allow_no_value=self.allow_no_value,
Expand All @@ -56,6 +56,7 @@ def newconfig(self, defaults=None):
default_section=self.default_section,
interpolation=self.interpolation,
)
arguments.update(kwargs)
instance = self.config_class(**arguments)
return instance

Expand Down Expand Up @@ -358,6 +359,13 @@ def test_basic(self):
the larch {0[1]} 1
""".format(self.delimiters)))

def test_space_delimiter(self):
# gh-156353: Space should be accepted as a delimiter
cf = self.newconfig(delimiters=(' ', '='))
cf.read_string("[all]\nfoo bar=baz")
self.assertEqual(cf.options('all'), ['foo'])
self.assertEqual(cf.get('all', 'foo'), 'bar=baz')

def test_basic_from_dict(self):
config = {
"Foo Bar": {
Expand Down Expand Up @@ -1991,8 +1999,8 @@ class ConvertersTestCase(BasicTestCase, unittest.TestCase):

config_class = configparser.ConfigParser

def newconfig(self, defaults=None):
instance = super().newconfig(defaults=defaults)
def newconfig(self, defaults=None, **kwargs):
instance = super().newconfig(defaults=defaults, **kwargs)
instance.converters['list'] = lambda v: [e.strip() for e in v.split()
if e.strip()]
return instance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`configparser` space delimiter parsing when using ``delimiters=(' ', '=')``.
Loading