From 5f303202ee0666f5298ff39a5a129162b69ff790 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Jun 2025 01:08:07 -0400 Subject: [PATCH 1/2] Test a quoted config var with meaningful edge whitespace #2035 fixed issue #1923 by removing separate double quotation marks appearing on a single-line configuration variable when parsing a configuration file. However, it also stripped leading and trailing whitespace from the string obtained by removing the quotes. This adds a test case of a plausible scenario where such whitespace needs to be preserved and where a user would almost certainly expect it to preserve: setting a value like `# ` for `core.commentString`, in order to be able to easily create commit messages like this one, that contain a line that begins with a literal `#`, while still letting `#` in the more common case that it is followed by a space be interpreted as a comment. The effect of `git config --local core.commentString '# '` is to add a `commentString = "# "` line in the `[core]` section of `.git/config`. The changes in #2035 allow us to correctly parse more quoted strings than before, and almost allow us to parse this, but not quite, because of the `strip()` operation that turns `# ` into `#`. --- test/fixtures/git_config_with_quotes_whitespace | 2 ++ test/test_config.py | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 test/fixtures/git_config_with_quotes_whitespace diff --git a/test/fixtures/git_config_with_quotes_whitespace b/test/fixtures/git_config_with_quotes_whitespace new file mode 100644 index 000000000..c6014cc61 --- /dev/null +++ b/test/fixtures/git_config_with_quotes_whitespace @@ -0,0 +1,2 @@ +[core] + commentString = "# " diff --git a/test/test_config.py b/test/test_config.py index 886d5b136..671f34046 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -412,6 +412,10 @@ def test_config_with_quotes(self): self.assertEqual(cr.get("user", "name"), "Cody Veal") 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) + self.assertEqual(cr.get("core", "commentString"), "# ") + 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) From bd2b930503ad5d97322aa81d7610ab743d915f84 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Jun 2025 00:13:46 -0400 Subject: [PATCH 2/2] Preserve quoted leading and trailing single-line whitespace At least in a single line, whitespace in a double-quoted value in a configuration file, like `name = " abc def "`, would presumably be intended. This removes the `strip()` call that is applied to text `ConfigParser` obtained by removing the double quotes around it. This slightly refines the changes in #2035 by dropping the `strip()` call while continuing to remove opening and closing double quotes. --- git/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/config.py b/git/config.py index 2df99a753..1d58db53a 100644 --- a/git/config.py +++ b/git/config.py @@ -509,7 +509,7 @@ def string_decode(v: str) -> str: is_multi_line = True optval = string_decode(optval[1:]) elif len(optval) > 1 and optval[0] == '"' and optval[-1] == '"': - optval = optval[1:-1].strip() + optval = optval[1:-1] # END handle multi-line # Preserves multiple values for duplicate optnames. cursect.add(optname, optval) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy