Skip to content

Preserve quoted leading and trailing single-line config var whitespace #2036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 `#`.
  • Loading branch information
EliahKagan committed Jun 7, 2025
commit 5f303202ee0666f5298ff39a5a129162b69ff790
2 changes: 2 additions & 0 deletions test/fixtures/git_config_with_quotes_whitespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
commentString = "# "
4 changes: 4 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ def test_config_with_quotes(self):
self.assertEqual(cr.get("user", "name"), "Cody Veal")
self.assertEqual(cr.get("user", "email"), "[email protected]")

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)
Expand Down
Loading