Skip to content

Incorrect handling of backslashes in Git configuration #45

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 0 commits into from
Feb 8, 2012
Merged

Conversation

ereOn
Copy link

@ereOn ereOn commented Feb 7, 2012

Steps to reproduce the issue:

import git
config = 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/config

Indeed, if you open .git/config you can see that the value is written as:

[test]
  test = some\data

While 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.

I provided a sample fixing commit: changes are simple but I couldn't test it (I have no access to any Python installation right now and did the change online).

@ereOn
Copy link
Author

ereOn commented Feb 7, 2012

Note: Don't pull the changes !

I couldn't test it but remembered too late that r'\' is not valid and should be '\\'.

Tell me if you want me to provide a full valid (and obviously tested) pull-request.

@Byron
Copy link
Member

Byron commented Feb 7, 2012

Thanks for digging into this - your report is thorough and very detailed.
Mistakes happen, and if you would amend the test-cases as well, I will be happy to merge it.

Thanks,
Sebastian

@ereOn
Copy link
Author

ereOn commented Feb 7, 2012

You are welcome.

I will provide a complete pull-request, including a modification of the test-cases, this evening or by tomorrow. (if I am given the time to do so).

Thank you for this great library :)

@ereOn ereOn merged commit 6e86f8a into gitpython-developers:master Feb 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants