Skip to content

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 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 3 commits into from
May 30, 2012
Merged

Conversation

ereOn
Copy link

@ereOn ereOn commented Feb 8, 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.

This pull request fixes both those issues and also fixes unescaped quotes pairs.

A test-case has been provided along with the fixes.

@Byron
Copy link
Member

Byron commented Mar 7, 2012

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.
However, if you are held off by the delay, please let me know.

@ereOn
Copy link
Author

ereOn commented Mar 8, 2012

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.

@ereOn
Copy link
Author

ereOn commented May 30, 2012

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

Byron added a commit that referenced this pull request May 30, 2012
Incorrect handling of backslashes and quotes in GitConfigParser

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.

This pull request fixes both those issues and also fixes unescaped quotes pairs.

A test-case has been provided along with the fixes.
@Byron Byron merged commit cd72d78 into gitpython-developers:master May 30, 2012
@Byron
Copy link
Member

Byron commented May 30, 2012

Thanks for bringing this up.
Had no time to test and/or verify it myself yet, but I will do this once I am back on the project.

Feel free to delete your clone, and
thanks for you work !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants