Allow round-tripping of malformed actors with angle brackets in commit objects #2178
+50
−20
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.
Fixes #2177
Problem
The
CommitRef::from_bytes()
method could successfully parse malformed commit data containing angle brackets (<>
) in actor email fields, butCommitRef::write_to()
would fail with anIllegalCharacter
error when attempting to serialize it back. This violated the principle that parsed objects should always be round-trippable.For example, parsing this real-world malformed commit data would succeed:
But writing it back would fail because the email field
gh <Gregor Hartmann<[email protected]>
contains angle brackets.Root Cause
The
validated_token
function ingix-actor
was rejecting any actor name or email containing<
,>
, or\n
characters. While this validation makes sense for newly created signatures, it prevented round-tripping of already-parsed malformed data that exists in real Git repositories.Solution
Modified the validation logic to allow angle brackets in actor names and emails while preserving format integrity:
<>
) in parsed actor data to enable round-tripping of malformed but real-world commit objects\n
) restriction since newlines would break the fundamental Git object format structureTesting
invalid_email_of_committer
now passesgix-actor
andgix-object
tests continue to passThis change ensures that any commit object that can be parsed can also be serialized back, maintaining data fidelity for real-world Git repositories containing malformed historical data.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.