GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: join backslash line continuations when reading config values by nkbeast · Pull Request #2227 · gitpython-developers/GitPython

Conversation

@nkbeast

@nkbeast nkbeast commented Sep 3, 2026

Copy link
Copy Markdown

git config joins an unquoted value that ends in a backslash with the next line: the backslash and the newline are removed and the next line is appended verbatim. Reproducing with git itself:

$ printf '[a]\n\tk = line1\\\n line2\n' > g.cfg
$ git config -f g.cfg a.k
line1 line2

GitPython only implemented multi-line values for quoted strings. For unquoted values the continuation line was silently dropped — GitConfigParser read back line1\ and the line2 content vanished, truncating whatever the user had stored (aliases, hook commands, any hand-edited multi-line value).

The fix reads the continuation inside _read and joins it, chaining across lines that themselves end in a backslash, with the exact rules git uses:

  • a single trailing backslash → continuation, next line appended verbatim (leading whitespace included)
  • an even number of trailing backslashes → an escaped one, value ends there (val\\\\ stays val\\\\)
  • a lone backslash right at end-of-file → dropped

All five cases are asserted against git's own output in the new test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nkbeast
nkbeast force-pushed the fix-config-backslash-continuation branch from 1f4913b to 22b4db5 Compare September 3, 2026 21:06
NK
fix: join backslash line continuations when reading config values
075a664
git config joins an unquoted value that ends in a backslash with the
next line: the backslash and the newline are removed and the next line
is appended verbatim, so 'k = line1\' followed by ' line2' reads back
as 'line1 line2'. GitPython only implemented multi-line values for
quoted strings; for unquoted values the continuation line was silently
dropped, truncating whatever was stored in the config.

Read the continuation inside _read and join it, chaining across lines
that themselves end in a backslash. An even number of trailing
backslashes is an escaped one, so the value ends there; a single
backslash right at end-of-file is dropped, matching git. Verified
against git itself for every case covered by the new tests.
@nkbeast
nkbeast force-pushed the fix-config-backslash-continuation branch from 22b4db5 to 075a664 Compare September 3, 2026 21:10
Byron and others added 2 commits September 4, 2026 06:26
@Byron @codex
fix: ignore continuation markers in config comments
60dd946
<!-- agent -->
Git treats # and ; outside quotes as the start of a comment. A trailing
backslash in that ignored text therefore cannot continue the value.

The continuation loop counted trailing slashes without lexical context, so
it consumed the next option and a later writable flush silently dropped that
setting.

- Track quote and escape state while checking the accumulated value.
- Stop continuation scanning at an unquoted comment.
- Cover preservation of the following option across a writable flush.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <[email protected]>
@Byron @codex
fix: parse joined config values as a whole
a15f791
Git removes each backslash-newline pair before parsing the resulting logical
value. Appending physical lines after processing only the first line left
trailing whitespace, comments, quotes, and recognized escapes literal.

That divergence returned values unlike git config and could preserve comment
text as configuration data.

- Accumulate continuation text before parsing it.
- Apply whitespace, comment, quote, and escape handling once to the complete value.
- Cover each affected syntax form with Git-compatible expectations.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <[email protected]>
@Byron

Byron commented Sep 4, 2026

Copy link
Copy Markdown
Member

Thanks!

As a note: The current Git configuration file parser is inherently insufficient and has many bugs. Fixing them all isn't the goal for GitPython 3.X, it's only remedy.
Version 4 will address these issues (much more) properly

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Byron
Byron merged commit 9ebf8b6 into gitpython-developers:main Sep 4, 2026
53 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@blaipr blaipr mentioned this pull request Sep 7, 2026
build: bump gitpython from 3.1.61 to 3.1.62 in /requirements ctrliq/ascender#846
Merged
@JingHao-Leon JingHao-Leon mentioned this pull request Oct 19, 2026
fix(config): decode escapes in unquoted config values #2297
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@nkbeast @Byron
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.