diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2017-01-26 21:46:19 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2017-01-26 21:46:19 +0000 |
commit | fe2f37b3c2f71e540f2974bf0bd853dcbe4b63d8 (patch) | |
tree | c8c711fda1b69fc41bb2999f6c57eb0b3364ba22 | |
parent | 38aca2675faa7e74ac7c6e515428cf1d310983bf (diff) |
Handle multi-line quoted values in config files. #495.
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | dulwich/config.py | 21 | ||||
-rw-r--r-- | dulwich/tests/test_config.py | 11 |
3 files changed, 24 insertions, 13 deletions
@@ -14,6 +14,11 @@ passed in. Allow passing in relative paths to porcelain.add().(Jelmer Vernooij) + BUG FIXES + + * Handle multi-line quoted values in config files. + (Jelmer Vernooij, #495) + 0.16.3 2016-01-14 TEST FIXES diff --git a/dulwich/config.py b/dulwich/config.py index 93c8d84d..ab944d44 100644 --- a/dulwich/config.py +++ b/dulwich/config.py @@ -307,23 +307,20 @@ class ConfigFile(ConfigDict): if not _check_variable_name(setting): raise ValueError("invalid variable name %s" % setting) if value.endswith(b"\\\n"): - value = value[:-2] - continuation = True + continuation = value[:-2] else: - continuation = False - value = _parse_string(value) - ret._values[section][setting] = value - if not continuation: + continuation = None + value = _parse_string(value) + ret._values[section][setting] = value setting = None else: # continuation line if line.endswith(b"\\\n"): - line = line[:-2] - continuation = True + continuation += line[:-2] else: - continuation = False - value = _parse_string(line) - ret._values[section][setting] += value - if not continuation: + continuation += line + value = _parse_string(continuation) + ret._values[section][setting] = value + continuation = None setting = None return ret diff --git a/dulwich/tests/test_config.py b/dulwich/tests/test_config.py index 431577d4..c60e1f7b 100644 --- a/dulwich/tests/test_config.py +++ b/dulwich/tests/test_config.py @@ -155,7 +155,6 @@ class ConfigFileTests(TestCase): cf = self.from_file(b"[branch.foo] foo = bar\n") self.assertEqual(b"bar", cf.get((b"branch", b"foo"), b"foo")) - #@expectedFailure def test_quoted(self): cf = self.from_file(b"""[gui] fontdiff = -family \\\"Ubuntu Mono\\\" -size 11 -weight normal -slant roman -underline 0 -overstrike 0 @@ -164,6 +163,16 @@ class ConfigFileTests(TestCase): b'fontdiff': b'-family "Ubuntu Mono" -size 11 -weight normal -slant roman -underline 0 -overstrike 0', }}), cf) + def test_quoted_multiline(self): + cf = self.from_file(b"""[alias] +who = \"!who() {\\ + git log --no-merges --pretty=format:'%an - %ae' $@ | sort | uniq -c | sort -rn;\\ +};\\ +who\" +""") + self.assertEqual(ConfigFile({(b'alias', ): { + b'who': b"!who() {git log --no-merges --pretty=format:'%an - %ae' $@ | sort | uniq -c | sort -rn;};who"}}), cf) + class ConfigDictTests(TestCase): |