Skip to content

Commit 5f30320

Browse files
committed
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 `#`.
1 parent 4dd5d45 commit 5f30320

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[core]
2+
commentString = "# "

test/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ def test_config_with_quotes(self):
412412
self.assertEqual(cr.get("user", "name"), "Cody Veal")
413413
self.assertEqual(cr.get("user", "email"), "[email protected]")
414414

415+
def test_config_with_quotes_with_literal_whitespace(self):
416+
cr = GitConfigParser(fixture_path("git_config_with_quotes_whitespace"), read_only=True)
417+
self.assertEqual(cr.get("core", "commentString"), "# ")
418+
415419
def test_get_values_works_without_requiring_any_other_calls_first(self):
416420
file_obj = self._to_memcache(fixture_path("git_config_multiple"))
417421
cr = GitConfigParser(file_obj, read_only=True)

0 commit comments

Comments
 (0)