Skip to content

bpo-33251: Prevent ConfigParser.items returning items present in vars. #6446

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 5 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
except KeyError:
if section != self.default_section:
raise NoSectionError(section)
orig_keys = list(d.keys())
# Update with the entry specific variables
if vars:
for key, value in vars.items():
Expand All @@ -854,7 +855,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
section, option, d[option], d)
if raw:
value_getter = lambda option: d[option]
return [(option, value_getter(option)) for option in d.keys()]
return [(option, value_getter(option)) for option in orig_keys]

def popitem(self):
"""Remove a section from the parser and return it as
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,7 @@ def test_items(self):
self.check_items_config([('default', '<default>'),
('getdefault', '|<default>|'),
('key', '|value|'),
('name', 'value'),
('value', 'value')])
('name', 'value')])
Copy link
Contributor

Choose a reason for hiding this comment

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

This proves this never worked. The test that added ('value', 'value') dates back to 2010 (Python 3.2).


def test_safe_interpolation(self):
# See http://www.python.org/sf/511737
Expand Down Expand Up @@ -1093,8 +1092,7 @@ def test_items(self):
self.check_items_config([('default', '<default>'),
('getdefault', '|%(default)s|'),
('key', '|%(name)s|'),
('name', '%(value)s'),
('value', 'value')])
('name', '%(value)s')])

def test_set_nonstring_types(self):
cf = self.newconfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`ConfigParser.items()` was fixed so that key-value pairs passed in via `vars`
are not included in the resulting output.