Skip to content

Commit 41aeadf

Browse files
committed
fix(configparser): restore space delimiter splitting option/value
Fix verified RED->GREEN. configparser regression: space delimiter no longer splits option/value at Lib/configparser.py:618 - delimiters=( , =) parsing foo bar=baz yields option foo bar instead of foo, new regex greedily consumes \s+word as part of option
1 parent 13ab4c2 commit 41aeadf

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

Lib/configparser.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,27 @@ def __init__(self, defaults=None, dict_type=_default_dict,
670670
self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
671671
else:
672672
d = "|".join(re.escape(d) for d in delimiters)
673-
if allow_no_value:
673+
if any(dl.strip() == "" for dl in delimiters):
674+
if allow_no_value:
675+
self._optcre = re.compile(
676+
r"""
677+
(?P<option>
678+
(?:(?!{delim})\S)+
679+
)
680+
\s*(?:
681+
(?P<vi>{delim})\s*
682+
(?P<value>.*))?$
683+
""".format(delim=d), re.VERBOSE)
684+
else:
685+
self._optcre = re.compile(
686+
r"""
687+
(?P<option>
688+
(?:(?!{delim})\S)+
689+
)
690+
\s*(?P<vi>{delim})\s*
691+
(?P<value>.*)$
692+
""".format(delim=d), re.VERBOSE)
693+
elif allow_no_value:
674694
self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d),
675695
re.VERBOSE)
676696
else:

0 commit comments

Comments
 (0)