Skip to content

gh-65697: Prevent configparser from writing keys it cannot properly read #129270

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 21 commits into from
Feb 23, 2025

Conversation

lincolnj1
Copy link
Contributor

@lincolnj1 lincolnj1 commented Jan 24, 2025

Prevents configparser from writing keys containing delimiters and keys beginning with the section header pattern to a file.

Both of those scenarios create .ini files the parser cannot accurately read back. Keys beginning with the section header pattern parse back as new sections. Keys containing delimiters parse back only the first portion as a key and the remainder as a value (i.e. key: 'one=two', value:'three' writes as 'one=two=three' and parses back as key: 'one', value: 'two=three').

Unsure on whether to handle newlines in key/section/values by rejecting them when writing, rejecting them when set, or escaping them when writing.

@lincolnj1 lincolnj1 requested a review from jaraco as a code owner January 24, 2025 21:49
@ghost
Copy link

ghost commented Jan 24, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2025

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.

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2025

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.

@lincolnj1 lincolnj1 changed the title gh-65697 gh-65697: Prevent configparser from writing keys it cannot properly read Jan 24, 2025
@lincolnj1 lincolnj1 marked this pull request as draft January 24, 2025 22:11
Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

The implementation looks sound and the tests seem to capture the essence of the change. I like it.

The only thing I'd like to see before accepting this - is there any lingering controversy? Who might oppose this change and can we get their consent?

If we can get consent from one or two of the most vocal detractors in the linked issues, then I'd say we could proceed. Otherwise, I'd like to hear their argument for what they recommend instead. Can you help gather that consensus?

@bedevere-app
Copy link

bedevere-app bot commented Jan 26, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@lincolnj1
Copy link
Contributor Author

lincolnj1 commented Jan 27, 2025

Thanks for reviewing, Jason!

The only thing I'd like to see before accepting this - is there any lingering controversy? Who might oppose this change and can we get their consent?

Newlines, \r, and \x00 are still unhandled and it seemed like the consensus was that they should be. I'm working on a fix atm but what I've tried (checking for \n,\r,\x00 in everything when writing) breaks older test cases. I may need to make a second pull request later to fix that.

@terryjreedy Do you have any thoughts on this change? You were pretty active in previous threads on this topic.

@bedevere-app
Copy link

bedevere-app bot commented Jan 27, 2025

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.

@lincolnj1
Copy link
Contributor Author

@bitdancer @vstinner Do you have any thoughts on this change? You both commented in previous threads on the topic.

@vstinner
Copy link
Member

cc @ambv

@jaraco
Copy link
Member

jaraco commented Feb 2, 2025

Let's give this until Mon, Feb 24 for comment. If there's no objection raised by then, we'll plan to proceed. If anyone needs more time, that's can be done too.

@bedevere-app
Copy link

bedevere-app bot commented Feb 15, 2025

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.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2025

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.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2025

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.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2025

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.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2025

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.

@lincolnj1 lincolnj1 marked this pull request as ready for review February 21, 2025 21:44
@jaraco jaraco merged commit 25a7ddf into python:main Feb 23, 2025
46 of 47 checks passed
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…erly read (python#129270)

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
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.

3 participants