Commit 71af3aa
fix: strip inline config comments the way git does
A `#` or `;` outside quotes starts a comment in git, with or without a
space before it and whether or not the value is quoted. The parser only
cut a `;` that was preceded by whitespace in an unquoted value, so
`name = Alice # work` read back with the comment attached, and
`k = "quoted" # after` was mistaken for an unterminated multi-line quote
and returned `quoted" # after`.
`parse_value` already implements git's rule, but it only ran when a
backslash continuation had been joined. Cut the comment before the
quote-structure branches, using the same quote- and escape-aware scan
that `is_line_continuation` uses, and let `parse_value` handle every
unquoted value rather than only continued ones.
That last part corrects one expectation in test_backslash_line_continuation:
`k = val\\` ends in an even number of backslashes, so it is an escaped
backslash rather than a continuation and the escape resolves.
`git config --get a.k` prints `val\`, where the test expected `val\\`.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent cf43820 commit 71af3aa
2 files changed
Lines changed: 47 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
514 | 532 | | |
515 | 533 | | |
516 | 534 | | |
| |||
575 | 593 | | |
576 | 594 | | |
577 | 595 | | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
| 596 | + | |
583 | 597 | | |
584 | 598 | | |
585 | 599 | | |
| |||
589 | 603 | | |
590 | 604 | | |
591 | 605 | | |
592 | | - | |
593 | 606 | | |
594 | 607 | | |
595 | 608 | | |
| |||
603 | 616 | | |
604 | 617 | | |
605 | 618 | | |
606 | | - | |
607 | | - | |
608 | | - | |
| 619 | + | |
609 | 620 | | |
610 | 621 | | |
611 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
242 | 265 | | |
243 | 266 | | |
244 | 267 | | |
| |||
250 | 273 | | |
251 | 274 | | |
252 | 275 | | |
253 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
254 | 280 | | |
255 | 281 | | |
256 | 282 | | |
| |||
0 commit comments