gitpython-developers/GitPython — pull request #46 by ereOn (2012-02-08 09:00:40+00:00)
Title: 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](http://linux.die.net/man/1/git-config) 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.