Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork941
Incorrect handling of backslashes and quotes in GitConfigParser#46
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for your effort ! As I want to give the merge more attention, I hope you are okay with me not merging it right away. |
No problem. I will leave the clone in my own Github account until you merge it. I'm not in a hurry for this fix (I applied the same fix in my code using GitPython, so things work for me now) but I guess other people are likely to face the same problem as it is easily reproducible. |
@Byron: Have you planned to merge this soon ? I intended to do some cleanup of my github account and I'm only keeping my clone of GitPython because of this pending pull-request. |
Incorrect handling of backslashes and quotes in GitConfigParserSteps to reproduce the issue:import gitconfig = git.Repo().config_writer()config.add_section('test')config.set_value('test', 'test', r'some\data')Now if you try to read this value using a regular (non Python) git config, Git complains that the configuration file is invalid:fatal: bad config file line 11 in .git/configIndeed, if you open .git/config you can see that the value is written as:[test] test = some\dataWhile the git-config configuration states that: String values may be entirely or partially enclosed in double quotes. You need to enclose variable values in double quotes if you want to preserve leading or trailing whitespace, or if the variable value contains comment characters (i.e. it contains # or ;). Double quote " and backslash \ characters in variable values must be escaped: use \" for " and \ for .That is, the backslashes are not escaped in the configuration file.This also causes issues while reading, because values are not un-escaped.This pull request fixes both those issues and also fixes unescaped quotes pairs.A test-case has been provided along with the fixes.
Thanks for bringing this up. Feel free to delete your clone, and |
Steps to reproduce the issue:
Now if you try to read this value using a regular (non Python)
git config
, Git complains that the configuration file is invalid:Indeed, if you open
.git/config
you can see that the value is written as:While the
git-config
configuration states that:That is, the backslashes are not escaped in the configuration file.
This also causes issues while reading, because values are not un-escaped.
This pull request fixes both those issues and also fixes unescaped quotes pairs.
A test-case has been provided along with the fixes.