Repository navigation
Commit 983e182
fix(config): decode escapes in unquoted config values
Git decodes the standard escape sequences in unquoted config values, but
`GitConfigParser._read` only called `parse_value()` when a value continued
onto a following line. A single-line unquoted value therefore kept its
escapes literal, so `b = first\nsecond` read back as `first\nsecond`
rather than `first<LF>second`.
The same value also decoded differently depending only on whether it was
wrapped: `b = first\nsecond \` continued onto a second line already went
through `parse_value()` and was decoded.
The missing decode made writes unsafe. The parsed value held no control
character, so the writer's CR/LF/NUL guard did not trigger, and saving an
unrelated key emitted a value that git then read differently than before.
With the escape decoded, the existing guard rejects the value instead of
corrupting the file.
A value is decoded only when every backslash in it introduces a known
escape. Git rejects an unknown escape outright, so GitPython never had to
handle one; it tolerates them instead, which is what keeps a Windows path
such as `C:\Users\me` usable. Decoding unconditionally would have broken
that: the `\t` of `\Temp\test_foo` would become a tab while the `\U` of
`\Users` stayed literal, mangling the path. Guarding on the whole value
decodes `a\tb` and `foo\\bar` as git does and leaves the path alone.
An existing case in `test_backslash_line_continuation` asserted the
undecoded spelling `val\\` for `k = val\\` followed by a newline. Git
yields `val\` there, since the second backslash escapes the first, so
that expectation is corrected to match.
Checked against git 2.50.1 (Apple Git-155).
Co-Authored-By: Codex <codex@openai.com>1 parent 9d3aff0 commit 983e182
3 files changed
Lines changed: 70 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
| |||
530 | 537 | | |
531 | 538 | | |
532 | 539 | | |
533 | | - | |
534 | 540 | | |
535 | 541 | | |
536 | | - | |
| 542 | + | |
537 | 543 | | |
538 | 544 | | |
539 | 545 | | |
| |||
552 | 558 | | |
553 | 559 | | |
554 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
555 | 581 | | |
556 | 582 | | |
557 | 583 | | |
| |||
606 | 632 | | |
607 | 633 | | |
608 | 634 | | |
609 | | - | |
610 | 635 | | |
611 | 636 | | |
612 | 637 | | |
| |||
620 | 645 | | |
621 | 646 | | |
622 | 647 | | |
623 | | - | |
624 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
625 | 653 | | |
626 | 654 | | |
627 | 655 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| |||
1209 | 1209 | | |
1210 | 1210 | | |
1211 | 1211 | | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
1212 | 1236 | | |
1213 | 1237 | | |
1214 | 1238 | | |
| |||
0 commit comments