Fix ini.set_option deleting indented options#69689
Open
ggiesen wants to merge 2 commits into
Open
Conversation
In _Section.refresh, an indented line was appended to the previous option's value, but when a section began with indented options (no prior option to append to) the line hit 'continue' and was silently discarded. Move the 'continue' inside the append branch so orphaned indented lines fall through to the normal key/value match and are preserved. Fixes saltstack#36354
The direct test calls _Section.refresh() itself the way _Ini.refresh does in production (section body passed positionally as inicontents with separator="=", refresh() invoked with no arguments) on a git-style section whose options are all indented, which the old code silently dropped. The inverse test guards against overcorrection by verifying an indented line following a normal option is still folded into that option's value as a continuation line rather than parsed as a separate entry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Defect: in salt/modules/ini_manage.py _Section.refresh, an indented config line (e.g. git-style ' url = ...') was meant to be appended to the previous option's value, but when a section began with indented options and had no prior option to append to, the code hit 'continue' and silently discarded the line before gen_ini rewrote the file, so set_option on another section deleted those options. Fix moves the 'continue' inside the 'if options:' branch so orphaned indented lines fall through to the normal key/value regex match and are preserved (indentation is dropped on round-trip, which matches the issue's accepted outcome). Added a regression test with the git-config fixture; verified it passes with the fix and, via a direct functional check, that both indented options come back as None on the unpatched code.
What issues does this PR fix or reference?
Fixes #36354
Previous Behavior
See #36354.
New Behavior
Fix ini.set_option deleting indented options. Validated by a unit test proven to fail on unpatched 3006.x and pass with the fix (confirmed by adversarial review).
Merge requirements satisfied?
Commits signed with GPG?
No