Skip to content

fix(configparser): restore space delimiter splitting option/value - #156375

Closed
shoemoney wants to merge 2 commits into
python:mainfrom
shoemoney:fix/configparser-space-delimiter
Closed

fix(configparser): restore space delimiter splitting option/value#156375
shoemoney wants to merge 2 commits into
python:mainfrom
shoemoney:fix/configparser-space-delimiter

Conversation

@shoemoney

Copy link
Copy Markdown

Fixes regression where space delimiter no longer splits option/value.

Bug: with delimiters=(' ', '=') parsing "foo bar=baz" yields option "foo bar" instead of "foo". The new regex from PR 146399 greedily consumes \s+word as part of option.

Fix: detect whitespace delimiters and use single-token option pattern for that case, preserving ReDoS protection for normal delimiters while restoring correct split. Multi-word options still work when delimiter is "=" or ":".

Evidence: RED->GREEN verified: before fix "foo bar=baz" -> option "foo bar", after fix -> option "foo", value "bar=baz". Normal case "foo bar = baz" with (=,:) still yields "foo bar".

Written in conjunction with my pair programmer Claude.

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
@shoemoney
shoemoney requested a review from jaraco as a code owner August 25, 2026 18:00
@bedevere-app

bedevere-app Bot commented Aug 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Comment thread Lib/configparser.py
if allow_no_value:
if any(dl.strip() == "" for dl in delimiters):
if allow_no_value:
self._optcre = re.compile(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fix the pattern that was broken, instead of adding yet another one?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The broken pattern is _OPT_TMPL/_OPT_NV_TMPL where (?:\s+(?:(?!{delim})\S)+)* greedily treats space-separated tokens as part of option. When space itself is a delimiter (delimiters=(' ', '=')) that continuation should not apply, the delimiter is the word boundary not part of option. A single regex that handles both would need a conditional inside the pattern on whether delimiter contains whitespace, which is the same branching but hidden inside the regex and harder to read plus risky for the ReDoS-safe backtracking the original fix (PR 146399) added. This keeps two small patterns: single-token option for whitespace delimiters, multi-word for =/:. Happy to unify into one template with a conditional if you prefer.

@shoemoney

Copy link
Copy Markdown
Author

CLA: The commit author jeremy@shoemoney.com (@shoemoney) needs to sign the Python CLA at https://cla.python.org/ . This is not auto-signable, the author must authenticate via GitHub at that URL and sign. The CLA check is pre-existing and not introduced by this PR. Once signed the bot will re-check.

@shoemoney

Copy link
Copy Markdown
Author

Reply to @StanFromIreland on why a second pattern: the issue is the (\s+word)* continuation in _OPT_TMPL assumes space is not a delimiter. When space is a delimiter, that continuation consumes bar as option instead of stopping at the delimiter. A fix inside the same regex would need a whitespace-delimiter conditional anyway, same branch but obscured inside the regex and entangled with the ReDoS-safe backtracking from PR 146399. This keeps single-token for whitespace delimiters and multi-word for =/: separate, minimal, and reviewable. Can unify if you would prefer a single templated pattern with a comment.

@shoemoney

Copy link
Copy Markdown
Author

Note: bedevere/issue-number still fails because this fix has no linked issue number. A maintainer can apply the skip issue label if this is intentional as a regression fix for PR 146399, or retitle with gh-156375 if an issue is filed.

@StanFromIreland

Copy link
Copy Markdown
Member

CLA: The commit author jeremy@shoemoney.com (@shoemoney) needs to sign the Python CLA at https://cla.python.org/ . This is not auto-signable, the author must authenticate via GitHub at that URL and sign. The CLA check is pre-existing and not introduced by this PR. Once signed the bot will re-check.

Are you an agent? We can't continue till the CLA is signed.

@StanFromIreland
StanFromIreland marked this pull request as draft August 26, 2026 09:06
@StanFromIreland

Copy link
Copy Markdown
Member

Closing in favour of #156382.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants