Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix GitConfigParser not removing quotes from values#2035

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

betaboon
Copy link
Contributor

closes#1923

@betaboonbetaboonforce-pushed thefix-configparser-quotes branch fromd233b4c to67468a2CompareJune 6, 2025 20:47
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

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

That's great, thank you!

@ByronByron merged commit4dd5d45 intogitpython-developers:mainJun 7, 2025
26 checks passed
Copy link
Member

@EliahKaganEliahKagan left a comment
edited
Loading

Choose a reason for hiding this comment

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

I think this change is an improvement and is better than what we had before, but I also worry that it may break some existing code that uses GitPython, because it leaves various other shortcomings intact while also making their presence harder to detect.

The contents of a quoted value are not, in general, intended to be interpreted literally. For example, if programs are handling double-quoted strings themselves and handling\ sequences in them, then removing the quotes here without handling\ sequences will break that: those programs will go from working correctly to working incorrectly when they upgrade to the next version of GitPython.

That doesn't mean this change isn't worthwhile, but it makes me think we should go further in supporting the syntax of Git configuration files. I also wonder if we should really be handling the single-line and multi-line cases separately as we are, since, if I understand correctly, they are parsed in a unified way by Git and not as separate cases.
 
The\n,\t, various other\ sequences, treatment of unrecognized\ sequences as errors, and various other differences between what we have here and what Git does can be seen in theparse_value function in Git.

It's possible that I'm missing something.GitConfigParser is probably the part of the GitPython code that I have done the least with. If I open a PR to make changes here before receiving feedback, then I'll wait for a review before merging it.

EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 7, 2025
gitpython-developers#2035 fixed issuegitpython-developers#1923 by removing separate double quotation marksappearing on a single-line configuration variable when parsing aa configuration file. However, it also stripped leading and trailingwhitespace from the string obtained by removing the quotes.This adds a test case of a plausible scenario where such whitespaceneeds to be preserved and where a user would almost certainly expectit to preserve: setting a value like `# ` for `core.commentString`,in order to be able to easily create commit messages like this one,that contain a line that begins with a literal `#`, while stillletting `#` in the more common case that it is followed by a spacebe interpreted as a comment.The effect of  `git config --local core.commentString '# '` is toadd a `commentString = "# "` line in the `[core]` section of`.git/config`. The changes ingitpython-developers#2035 allow us to correctly parsemore quoted strings than before, and almost allow us to parse this,but not quite, because of the `strip()` operation that turns `# `into `#`.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 7, 2025
At least in a single line, whitespace in a double-quoted value in aconfiguration file, like `name = " abc def "`, would presumably beintended. This removes the `strip()` call that is applied to text`ConfigParser` obtained by removing the double quotes around it.This slightly refines the changes ingitpython-developers#2035 by dropping the `strip()`call while continuing to remove opening and closing double quotes.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 7, 2025
gitpython-developers#2035 fixed issuegitpython-developers#1923 by removing separate double quotation marksappearing on a single-line configuration variable when parsing aconfiguration file. However, it also stripped leading and trailingwhitespace from the string obtained by removing the quotes.This adds a test case of a plausible scenario where such whitespaceneeds to be preserved and where a user would almost certainly expectit to preserve: setting a value like `# ` for `core.commentString`,in order to be able to easily create commit messages like this one,that contain a line that begins with a literal `#`, while stillletting `#` in the more common case that it is followed by a spacebe interpreted as a comment.The effect of  `git config --local core.commentString '# '` is toadd a `commentString = "# "` line in the `[core]` section of`.git/config`. The changes ingitpython-developers#2035 allow us to correctly parsemore quoted strings than before, and almost allow us to parse this,but not quite, because of the `strip()` operation that turns `# `into `#`.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 7, 2025
At least in a single line, whitespace in a double-quoted value in aconfiguration file, like `name = " abc def "`, would presumably beintended. This removes the `strip()` call that is applied to text`ConfigParser` obtained by removing the double quotes around it.This slightly refines the changes ingitpython-developers#2035 by dropping the `strip()`call while continuing to remove opening and closing double quotes.
@Byron
Copy link
Member

@betaboon Maybe you could provide us with a follow-up PR that handles the escape sequences which may be present inside of quoted values, to more correctly capture this.

After all, the GitPython Git configuration parser is just an adapted INI parser, and that is inherently unable to capture all the subtleties, but we can try harder where we can - this is clearly one such opportunity.

For anything serious, it's better to usegitoxide which fully captures Git configuration files.

EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
The ConfigParser has supported this for a long time, but it is nowdone redundantly sincegitpython-developers#2035. This adds a test for it, both to makeclearer that it is intended to work and to allow verifying that itcontinues to hold once the legacy special-casing for it is removed.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
The ConfigParser has supported this for a long time, but it is nowdone redundantly sincegitpython-developers#2035. This adds a test for it, both to makeclearer that it is intended to work and to allow verifying that itcontinues to hold once the legacy special-casing for it is removed.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
Because `""` is a special case of `"..."` as parsed sincegitpython-developers#2035.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
This is for single line quoting in the ConfigParser.This leaves the changes ingitpython-developers#2035 (as adjusted ingitpython-developers#2036) intact forthe cases where it addressedgitpython-developers#1923: when the `...` in `"..."`(appearing in the value position on a single `{name} = {value}"`line) has no occurrences of `\` or `"`, quote removal is enough.But when `\` or `"` does appear, this suppresses quote removal.This is with the idea that, while it would be better to interpretsuch lines as Git does, we do not yet do that, so it is preferableto return the same results we have in the past (which some programsmay already be handling themselves).This should make the test introduced in the preceding commit pass.But it will be even better to support more syntax, at leastwell-formed escapes. As noted in the test, both the test and thecode under test can be adjusted for that.(See comments ingitpython-developers#2035 for context.)
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
Because literal `""` is a special case of `"..."` as parsedsincegitpython-developers#2035.
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
This is for single line quoting in the ConfigParser.This leaves the changes ingitpython-developers#2035 (as adjusted ingitpython-developers#2036) intact forthe cases where it addressedgitpython-developers#1923: when the `...` in `"..."`(appearing in the value position on a single `{name} = {value}"`line) has no occurrences of `\` or `"`, quote removal is enough.But when `\` or `"` does appear, this suppresses quote removal.This is with the idea that, while it would be better to interpretsuch lines as Git does, we do not yet do that, so it is preferableto return the same results we have in the past (which some programsmay already be handling themselves).This should make the test introduced in the preceding commit pass.But it will be even better to support more syntax, at leastwell-formed escapes. As noted in the test, both the test and thecode under test can be adjusted for that.(See comments ingitpython-developers#2035 for context.)
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
This is for single line quoting in the ConfigParser.This leaves the changes ingitpython-developers#2035 (as adjusted ingitpython-developers#2036) intact forthe cases where it addressedgitpython-developers#1923: when the `...` in `"..."`(appearing in the value position on a single `{name} = {value}"`line) has no occurrences of `\` or `"`, quote removal is enough.But when `\` or `"` does appear, this suppresses quote removal.This is with the idea that, while it would be better to interpretsuch lines as Git does, we do not yet do that, so it is preferableto return the same results we have in the past (which some programsmay already be handling themselves).This should make the test introduced in the preceding commit pass.But it will be even better to support more syntax, at leastwell-formed escapes. As noted in the test, both the test and thecode under test can be adjusted for that.(See comments ingitpython-developers#2035 for context.)
@betaboon
Copy link
ContributorAuthor

@EliahKagan beat me to it. thanks a bunch.

@EliahKagan
Copy link
Member

EliahKagan commentedJun 8, 2025
edited
Loading

I actually have not implemented handling of escape sequences. If you mean#2048, that detects if the string may contain escape sequences (or if it may have a closing quotation mark before the one at the end of the line). If so, avoids removing the outer quotes at all. Otherwise, it allows them to be removed.

For example, if we merge#2048, then:

  • "John Smith" becomesJohn Smith, as it did since this PR (#2035) fixed#1923. That outcome is fully correct already, and#2048 avoids changing it.
  • "John\tSmith" stays as"John\tSmith", rather than becomingJohn\tSmith as it has since this PR (#2035). But the better effect would be for it to becomeJohnSmith (i.e.John followed by a tab character followed bySmith, and with the quotes removed).

While that should be enough to avoid breaking existing code as described in#2035 (review), it is not as good as actually translating the escape sequences as suggested in#2035 (comment).

The fiverecognized escape sequences for double-quoted values in Git configuration files are described in the last paragraph ofthe "Syntax" section ofgit-config(1):

The following escape sequences (beside\" and\\) are recognized:\n for newline character (NL),\t for horizontal tabulation (HT, TAB) and\b for backspace (BS). Other char escape sequences (including octal escape sequences) are invalid.

You are certainly under no obligation! However, if you are interested in adding handling for escape sequences, then I think you could still do so--either after, or instead of,#2048--and hopefully nothing I have done would get in the way. (Actually, I think#2048 might make it easier to proceed with adding translation of escape sequences, or other changes.)

@betaboon
Copy link
ContributorAuthor

i took a look at#2048. that seems like a good way forward.
if i find the time to attempt resolving escape sequences, i think it makes sense to do it after#2048.

tbh: i never anticipated my (seemingly trivial) change from#2035 to start this rabbit hole. I'm glad you caught this.

just for clarity: if after#2048 you feel like going ahead for the escape sequences, go ahead. i really can't promise i find the time to do so any time soon.

Byron reacted with thumbs up emoji

EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
This is for single line quoting in the ConfigParser.This leaves the changes ingitpython-developers#2035 (as adjusted ingitpython-developers#2036) intact forthe cases where it addressedgitpython-developers#1923: when the `...` in `"..."`(appearing in the value position on a single `{name} = {value}"`line) has no occurrences of `\` or `"`, quote removal is enough.But when `\` or `"` does appear, this suppresses quote removal.This is with the idea that, while it would be better to interpretsuch lines as Git does, we do not yet do that, so it is preferableto return the same results we have in the past (which some programsmay already be handling themselves).This should make the test introduced in the preceding commit pass.But it will be even better to support more syntax, at leastwell-formed escapes. As noted in the test, both the test and thecode under test can be adjusted for that.(See comments ingitpython-developers#2035 for context.)
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull requestJun 8, 2025
This is for single line quoting in the ConfigParser.This leaves the changes ingitpython-developers#2035 (as adjusted ingitpython-developers#2036) intact forthe cases where it addressedgitpython-developers#1923: when the `...` in `"..."`(appearing in the value position on a single `{name} = {value}"`line) has no occurrences of `\` or `"`, quote removal is enough.But when `\` or `"` does appear, this suppresses quote removal.This is with the idea that, while it would be better to interpretsuch lines as Git does, we do not yet do that, so it is preferableto return the same results we have in the past (which some programsmay already be handling themselves).This should make the test introduced in the preceding commit pass.But it will be even better to support more syntax, at leastwell-formed escapes. As noted in the test, both the test and thecode under test can be adjusted for that.(See comments ingitpython-developers#2035 for context.)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron approved these changes

@EliahKaganEliahKaganEliahKagan left review comments

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

GitConfigParser misparses quotes in options
3 participants
@betaboon@Byron@EliahKagan

[8]ページ先頭

©2009-2025 Movatter.jp