8000 gh-65697: Improved error msg for configparser key validation by lincolnj1 · Pull Request #135527 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-65697: Improved error msg for configparser key validation #135527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Properly added change to configparser
  • Loading branch information
lincolnj1 committed Jun 15, 2025
commit 1c04d28f4a2d130a355139a1b0590f2375023d38
11 changes: 7 additions & 4 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,14 @@ def _convert_to_boolean(self, value):

def _validate_key_contents(self, key):
"""Raises an InvalidWriteError for any keys containing
delimiters or that match the section header pattern"""
delimiters or that begins with the section header pattern"""
if re.match(self.SECTCRE, key):
raise InvalidWriteError("Cannot write keys matching section pattern")
if any(delim in key for delim in self._delimiters):
raise InvalidWriteError("Cannot write key that contains delimiters")
raise InvalidWriteError(
f"Cannot write key {key}; begins with section pattern")
for delim in self._delimiters:
if delim in key:
raise InvalidWriteError(
f"Cannot write key {key}; contains delimiter {delim}")

def _validate_value_types(self, *, section="", option="", value=""):
"""Raises a TypeError for illegal non-string values.
Expand Down
Loading
0