From e5a2db58d4d7fee765bd1146647bf2c09b026ce8 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Jun 2025 19:24:31 -0400 Subject: [PATCH] Test `ConfigParser` with whitespace outside the value In both the: - Unquoted case, where extra whitespace is at the edges of what can be parsed as the value. - Quoted case, where extra whitespace is next to but outside of the quotes. The case where the whitespace is at the edges of the quoted value and *inside* the quotes, and thus part of the value, is already covered in #2036. (That is merely renamed here, to distinguish it.) --- test/fixtures/git_config_with_extra_whitespace | 2 ++ ...espace => git_config_with_quotes_whitespace_inside} | 0 .../fixtures/git_config_with_quotes_whitespace_outside | 2 ++ test/test_config.py | 10 +++++++++- 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/git_config_with_extra_whitespace rename test/fixtures/{git_config_with_quotes_whitespace => git_config_with_quotes_whitespace_inside} (100%) create mode 100644 test/fixtures/git_config_with_quotes_whitespace_outside diff --git a/test/fixtures/git_config_with_extra_whitespace b/test/fixtures/git_config_with_extra_whitespace new file mode 100644 index 000000000..0f727cb5d --- /dev/null +++ b/test/fixtures/git_config_with_extra_whitespace @@ -0,0 +1,2 @@ +[init] + defaultBranch = trunk diff --git a/test/fixtures/git_config_with_quotes_whitespace b/test/fixtures/git_config_with_quotes_whitespace_inside similarity index 100% rename from test/fixtures/git_config_with_quotes_whitespace rename to test/fixtures/git_config_with_quotes_whitespace_inside diff --git a/test/fixtures/git_config_with_quotes_whitespace_outside b/test/fixtures/git_config_with_quotes_whitespace_outside new file mode 100644 index 000000000..4b1615a51 --- /dev/null +++ b/test/fixtures/git_config_with_quotes_whitespace_outside @@ -0,0 +1,2 @@ +[init] + defaultBranch = "trunk" diff --git a/test/test_config.py b/test/test_config.py index 671f34046..879b98365 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -398,6 +398,10 @@ def test_complex_aliases(self): self._to_memcache(fixture_path(".gitconfig")).getvalue(), ) + def test_config_with_extra_whitespace(self): + cr = GitConfigParser(fixture_path("git_config_with_extra_whitespace"), read_only=True) + self.assertEqual(cr.get("init", "defaultBranch"), "trunk") + def test_empty_config_value(self): cr = GitConfigParser(fixture_path("git_config_with_empty_value"), read_only=True) @@ -413,9 +417,13 @@ def test_config_with_quotes(self): self.assertEqual(cr.get("user", "email"), "cveal05@gmail.com") def test_config_with_quotes_with_literal_whitespace(self): - cr = GitConfigParser(fixture_path("git_config_with_quotes_whitespace"), read_only=True) + cr = GitConfigParser(fixture_path("git_config_with_quotes_whitespace_inside"), read_only=True) self.assertEqual(cr.get("core", "commentString"), "# ") + def test_config_with_quotes_with_whitespace_outside_value(self): + cr = GitConfigParser(fixture_path("git_config_with_quotes_whitespace_outside"), read_only=True) + self.assertEqual(cr.get("init", "defaultBranch"), "trunk") + 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)