summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorJulien Kauffmann <julien.kauffmann@freelan.org>2012-02-08 09:57:24 +0100
committerJulien Kauffmann <julien.kauffmann@freelan.org>2012-02-08 09:57:24 +0100
commit2b7975cab03ea76db412b9f8d35ef82286f25777 (patch)
treef86c35d735eafd6c766a78bd6dcb5b5e28a983cc /git
parentd78a82dc7cde20bb1010a4a4dbd6a48f6c1e37bb (diff)
downloadgitpython-2b7975cab03ea76db412b9f8d35ef82286f25777.tar.gz
Fixed quotes and backslashes handling in GitConfigParser
Diffstat (limited to 'git')
-rw-r--r--git/config.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/git/config.py b/git/config.py
index c71bb8ca..64031fdb 100644
--- a/git/config.py
+++ b/git/config.py
@@ -245,8 +245,23 @@ class GitConfigParser(cp.RawConfigParser, object):
if pos != -1 and optval[pos-1].isspace():
optval = optval[:pos]
optval = optval.strip()
- if optval == '""':
- optval = ''
+
+ # Remove paired unescaped-quotes
+ unquoted_optval = ''
+ escaped = False
+ in_quote = False
+ for c in optval:
+ if not escaped and c == '"':
+ in_quote = not in_quote
+ else:
+ escaped = (c == '\\')
+ unquoted_optval += c
+
+ optval = unquoted_optval
+
+ optval = optval.replace('\\\\', '\\') # Unescape backslashes
+ optval = optval.replace(r'\"', '"') # Unescape quotes
+
optname = self.optionxform(optname.rstrip())
cursect[optname] = optval
else:
@@ -303,7 +318,11 @@ class GitConfigParser(cp.RawConfigParser, object):
fp.write("[%s]\n" % name)
for (key, value) in section_dict.items():
if key != "__name__":
- fp.write("\t%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
+ value = str(value)
+ value = value.replace('\\', '\\\\') # Escape backslashes
+ value = value.replace('"', r'\"') # Escape quotes
+ value = value.replace('\n', '\n\t')
+ fp.write("\t%s = %s\n" % (key, value))
# END if key is not __name__
# END section writing