Repository navigation
plumbing: format/config, Quote values containing a CR - #2606
Merged
Merged
Conversation
This was referenced Nov 18, 2026
hiddeco
force-pushed
the
fix/config-encode-cr
branch
2 times, most recently
from
November 19, 2026 03:49
8072604 to
2e2b9e9
Compare
The encoder wrote a value holding a carriage return unquoted. A value ending in CR was then written as `key = foo<CR><LF>`, which Git reads as `foo` because it drops a CR before an LF, and gcfg drops every CR. The value written is not the value read, the mismatch behind CVE-2025-48384, where a submodule path ending in CR was truncated. Quote any value containing `\r`, as Git's `write_pair` does since 2.50.1. Git keeps a CR inside quotes, and so does gcfg v2.0.3, which only drops a CR that is followed by LF. Values with a trailing space, tab or newline were already quoted or escaped, and a form feed or vertical tab is not whitespace to Git, so none of those change. The CR round-trip test needs gcfg v2.0.3 (go-git/gcfg#20), which keeps a quoted CR. The encoder output test fails without this change either way. Assisted-by: Claude Sonnet 5.5 Signed-off-by: Hidde Beydals <[email protected]>
hiddeco
force-pushed
the
fix/config-encode-cr
branch
from
November 19, 2026 04:26
2e2b9e9 to
e27cf95
Compare
pjbgf
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The encoder wrote a value holding a carriage return unquoted. A value
ending in a CR was then written as
key = foo<CR><LF>, which Git readsas
foo, because it drops a CR directly before an LF, and which gcfgreads as
foo, because it drops every CR. The value written is not thevalue read. This is the mismatch behind CVE-2025-48384, where a
submodule path ending in a CR was truncated on read; Git fixed it in
2.50.1 by quoting values that contain a CR 1.
It matters for go-git before gcfg's CR handling changes. After
go-git/gcfg#20, a CR inside quotes is kept, so a quoted
"foo\r"readsback as
foo<CR>while an unquoted trailing CR is still dropped. Theencoder must quote it for the value to survive a write and read cycle.
What
Add
\rto the characters that makeencodeOptionsquote a value. Theother cases Git quotes were already covered: a leading or trailing
space,
;and#(and go-git also quotes",\, tab and newline,which Git backslash-escapes). A form feed or vertical tab is not
whitespace to Git and is left alone.
Compatibility
A value containing a CR is now written inside double quotes. Git reads
that back unchanged. Values without a CR encode exactly as before.
Release note
The config encoder now quotes values that contain a carriage return, as
Git does since 2.50.1. Previously
key = foo<CR>was written unquoted,and both Git and gcfg read it back as
foo.Tests
TestEncodeQuotesValuesGitQuoteschecks the encoder output for threeCR cases. It fails on
main.TestEncodeRoundTripsValuesWithCRencodes and decodes seven CRvalues and asserts the value comes back unchanged. It needs gcfg
v2.0.3 (gcfg: Read values the way git does around whitespace and CR gcfg#20), which keeps a quoted CR and which
mainalready pins; against v2.0.2 it fails.
Verified against git 2.54:
git config x.a $'foo\r'writes the value inquotes and reads it back unchanged.
Ordering
mainalready pins gcfg v2.0.3, which contains go-git/gcfg#20, so theencoder and the reader agree on a quoted CR once this lands. Both this PR and #2607 (
Refuse names Git refuses) addtests at the end of
encoder_test.go, so the second to merge needs atrivial rebase.
AI assistance: Claude Sonnet 5.5 (see the
Assisted-bytrailer).