From 67468a2396f56f792ac4c139f43c98745e93a2b5 Mon Sep 17 00:00:00 2001 From: betaboon Date: Fri, 6 Jun 2025 22:41:28 +0200 Subject: [PATCH] Fix GitConfigParser not removing quotes from values --- git/config.py | 2 ++ test/fixtures/git_config_with_quotes | 3 +++ test/test_config.py | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/git_config_with_quotes diff --git a/git/config.py b/git/config.py index de3508360..2df99a753 100644 --- a/git/config.py +++ b/git/config.py @@ -508,6 +508,8 @@ def string_decode(v: str) -> str: if len(optval) > 1 and optval[0] == '"' and optval[-1] != '"': is_multi_line = True optval = string_decode(optval[1:]) + elif len(optval) > 1 and optval[0] == '"' and optval[-1] == '"': + optval = optval[1:-1].strip() # END handle multi-line # Preserves multiple values for duplicate optnames. cursect.add(optname, optval) diff --git a/test/fixtures/git_config_with_quotes b/test/fixtures/git_config_with_quotes new file mode 100644 index 000000000..40e6710d9 --- /dev/null +++ b/test/fixtures/git_config_with_quotes @@ -0,0 +1,3 @@ +[user] + name = "Cody Veal" + email = "cveal05@gmail.com" diff --git a/test/test_config.py b/test/test_config.py index 92997422d..886d5b136 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -391,7 +391,7 @@ def test_complex_aliases(self): with GitConfigParser(file_obj, read_only=False) as w_config: self.assertEqual( w_config.get("alias", "rbi"), - '"!g() { git rebase -i origin/${1:-master} ; } ; g"', + "!g() { git rebase -i origin/${1:-master} ; } ; g", ) self.assertEqual( file_obj.getvalue(), @@ -406,6 +406,12 @@ def test_empty_config_value(self): with self.assertRaises(cp.NoOptionError): cr.get_value("color", "ui") + def test_config_with_quotes(self): + cr = GitConfigParser(fixture_path("git_config_with_quotes"), read_only=True) + + self.assertEqual(cr.get("user", "name"), "Cody Veal") + self.assertEqual(cr.get("user", "email"), "cveal05@gmail.com") + def test_get_values_works_without_requiring_any_other_calls_first(self): file_obj = self._to_memcache(fixture_path("git_config_multiple")) cr = GitConfigParser(file_obj, read_only=True)