Skip to content

Commit f2b8041

Browse files
committed
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.)
1 parent 7bcea08 commit f2b8041

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

git/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,16 @@ def string_decode(v: str) -> str:
505505
optval = optval.strip()
506506

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

516519
# Preserves multiple values for duplicate optnames.
517520
cursect.add(optname, optval)

0 commit comments

Comments
 (0)