Skip to content

Don't remove quotes if \ or " are present inside #2048

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
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
Prev Previous commit
Don't remove quotes if \ or " are present inside
This is for single line quoting in the ConfigParser.

This leaves the changes in #2035 (as adjusted in #2036) intact for
the cases where it addressed #1923: when the `...` in `"..."`
(appearing in the value position on a single `{name} = {value}"`
line) has no occurrences of `\` or `"`, quote removal is enough.

But when `\` or `"` does appear, this suppresses quote removal.
This is with the idea that, while it would be better to interpret
such lines as Git does, we do not yet do that, so it is preferable
to return the same results we have in the past (which some programs
may already be handling themselves).

This should make the test introduced in the preceding commit pass.
But it will be even better to support more syntax, at least
well-formed escapes. As noted in the test, both the test and the
code under test can be adjusted for that.

(See comments in #2035 for context.)
  • Loading branch information
EliahKagan committed Jun 8, 2025
commit f2b80410e96a256aed044fba0387eab0440a1525
9 changes: 6 additions & 3 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,16 @@ def string_decode(v: str) -> str:
optval = optval.strip()

if len(optval) < 2 or optval[0] != '"':
pass # Nothing to treat as opening quotation.
# Does not open quoting.
pass
elif optval[-1] != '"':
# Opens quoting and does not close: appears to start multi-line quoting.
is_multi_line = True
optval = string_decode(optval[1:])
# END handle multi-line
else:
elif optval.find("\\", 1, -1) == -1 and optval.find('"', 1, -1) == -1:
# Opens and closes quoting. Single line, and all we need is quote removal.
optval = optval[1:-1]
# TODO: Handle other quoted content, especially well-formed backslash escapes.

# Preserves multiple values for duplicate optnames.
cursect.add(optname, optval)
Expand Down
Loading