Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
454f026
Added check for delimiters in cfgparser keys to _validate_value_types
lincolnj1 Jan 16, 2025
20b24b1
Deleted some trailing whitespace
lincolnj1 Jan 22, 2025
5b730b6
Merge branch 'python:main' into fix-issue-128843
lincolnj1 Jan 22, 2025
9cc3506
Added check for section pattern in key and moved
lincolnj1 Jan 24, 2025
3638e67
Clarified _validate_key_contents() doc comment
lincolnj1 Jan 24, 2025
b161cea
Merge branch 'python:main' into fix-issue-128843
lincolnj1 Jan 24, 2025
f73d17a
Merge branch 'python:main' into fix-issue-128843
lincolnj1 Jan 24, 2025
5a47f44
Clarified new error name/doc comment and improved
lincolnj1 Jan 24, 2025
e12b696
Clarified InvalidWriteError doc comment
lincolnj1 Jan 24, 2025
f5f1cbb
Merge branch 'fix-issue-128843' of https://github.com/lincolnj1/cpyth…
lincolnj1 Jan 24, 2025
3d84347
Merge branch 'main' into validate-config-writes
lincolnj1 Jan 24, 2025
97c8e93
Remove trailing whitespace
lincolnj1 Jan 27, 2025
ea137d0
Adding documentation for InvalidWriteError
lincolnj1 Feb 15, 2025
7ca33c7
Remove trailing whitespace
lincolnj1 Feb 15, 2025
353eaf1
Cleaned up documentation on InvalidWriteError
lincolnj1 Feb 21, 2025
ccf715e
Merge branch 'main' into validate-config-writes
lincolnj1 Feb 21, 2025
a3e8848
Delint of test-configparser.py
lincolnj1 Feb 21, 2025
0e278fd
Removing trailing whitespace on line 2184 of test_configparser
lincolnj1 Feb 21, 2025
3da65ae
📜🤖 Added by blurb_it.
blurb-it[bot] Feb 21, 2025
aa9c92a
Changed formatting of configparser.py __all__
lincolnj1 Feb 21, 2025
b001df6
Merge branch 'validate-config-writes' of github.com:lincolnj1/cpython…
lincolnj1 Feb 21, 2025
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
Next Next commit
Added check for delimiters in cfgparser keys to _validate_value_types
  • Loading branch information
lincolnj1 committed Jan 16, 2025
commit 454f026b93543b92e15e7bc64387c26fd208be19
10 changes: 9 additions & 1 deletion Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"MultilineContinuationError", "UnnamedSectionDisabledError",
"ConfigParser", "RawConfigParser",
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
"SectionProxy", "ConverterMapping",
"SectionProxy", "ConverterMapping", "InvalidKeyError",
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH", "UNNAMED_SECTION")

_default_dict = dict
Expand Down Expand Up @@ -374,6 +374,11 @@ class _UnnamedSection:

def __repr__(self):
return "<UNNAMED_SECTION>"

class InvalidKeyError(Error):
"""Raised when attempting to write a key which contains any delimiters"""
def __init__(self):
Error.__init__(self, "Cannot write key that contains a delimiter")


UNNAMED_SECTION = _UnnamedSection()
Expand Down Expand Up @@ -1234,6 +1239,9 @@ def _validate_value_types(self, *, section="", option="", value=""):
if not self._allow_no_value or value:
if not isinstance(value, str):
raise TypeError("option values must be strings")
for delim in self._delimiters:
if delim in option:
raise InvalidKeyError()

@property
def converters(self):
Expand Down
13 changes: 12 additions & 1 deletion Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,18 @@ def test_disabled_error(self):

with self.assertRaises(configparser.UnnamedSectionDisabledError):
configparser.ConfigParser().add_section(configparser.UNNAMED_SECTION)


def test_invalid_key(self):
cfg2file = configparser.ConfigParser()
cfg2file.add_section("section1")
with self.assertRaises(configparser.InvalidKeyError):
cfg2file.set("section1", "one=two", "three")

with self.assertRaises(configparser.InvalidKeyError):
cfg2file.set("section1", "one:two", "three")

cfg2file.set("section1", "one", "two=three")


class MiscTestCase(unittest.TestCase):
def test__all__(self):
Expand Down