fix(configparser): restore space delimiter splitting option/value - #156375
fix(configparser): restore space delimiter splitting option/value#156375shoemoney wants to merge 2 commits into
Conversation
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
|
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 |
|
The following commit authors need to sign the Contributor License Agreement: |
| if allow_no_value: | ||
| if any(dl.strip() == "" for dl in delimiters): | ||
| if allow_no_value: | ||
| self._optcre = re.compile( |
There was a problem hiding this comment.
Why not fix the pattern that was broken, instead of adding yet another one?
There was a problem hiding this comment.
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.
|
CLA: The commit author |
|
Reply to @StanFromIreland on why a second pattern: the issue is the |
|
Note: |
Are you an agent? We can't continue till the CLA is signed. |
|
Closing in favour of #156382. |
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.