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

Conversation

EliahKagan
Copy link
Member

#2035 fixed issue #1923 by removing separate double quotation marks appearing on a single-line configuration variable when parsing a configuration file. However, as noted in #2035 (comment), it also stripped leading and trailing whitespace from the string obtained by removing the quotes.

In this PR:

  1. 5f30320 adds a test case of a plausible--and in my view, decisive--scenario where such whitespace needs to be preserved and where a user would almost certainly expect it to preserve. This test would also have failed before #2035, due to the absence of quote removal. But it is the sort of value that one would expect to parse correctly now that #1923 is fixed, and which #2035 almost does parse correctly.
  2. bd2b930 fixes the case by removing the strip() call while leaving the changes from #2035 otherwise intact. The test added in (1) fails until this change, and then passes.

See the commit message for further details.

gitpython-developers#2035 fixed issue gitpython-developers#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 gitpython-developers#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 `#`.
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 gitpython-developers#2035 by dropping the `strip()`
call while continuing to remove opening and closing double quotes.
@EliahKagan EliahKagan marked this pull request as ready for review June 7, 2025 05:31
@EliahKagan EliahKagan requested a review from Byron June 7, 2025 05:31
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this, a great catch!

@Byron Byron merged commit cf8029d into gitpython-developers:main Jun 7, 2025
26 checks passed
@EliahKagan EliahKagan deleted the quoted-whitespace branch June 7, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants