Skip to content

Refuse author values git would rewrite in WithAuthor [patch] - #240

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/239-author-ident-characters
Oct 18, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/239-author-ident-characters

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #239

Summary

  • Commit().WithAuthor(name, email) now throws ArgumentException when either value contains <, > or a control character (including \n, \r, \t, \0). The message names the bad value and ParamName says which argument it was. git splits or strips these characters silently and exits 0, so the commit used to record a different author than the one asked for.
  • I put the check in the builder rather than on GitAuthorName/GitAuthorEmail. Both types are also built by GitLogParser from identities read back out of history, and the GitAuthorEmail remarks say those must stay readable. A construction-time attribute would make Log() throw on a crafted historical commit.

Tests

  • RejectsAuthorValuesGitWouldRewrite: the three rows from the issue, plus >, \r, \0 and control characters in the email. All 8 cases fail with the builder change reverted and pass with it.
  • AcceptsOrdinaryAuthorValues: O'Brien, Jr. and non-ASCII names and emails are still passed through unchanged.
  • CommitWithAuthorRecordsAnOrdinaryAuthorAsGivenAsync (integration, real git): the author read back from the commit matches the one requested.
  • Full GitIntegration.Test suite: 894 passed, 0 skipped.

Generated by Claude Code

git splits "Name <email>" at the first '<' and the first '>' after it,
and strips '<', '>' and newlines from the name, all with exit code 0.
A name or email holding any of those, or another control character,
therefore recorded a different author than the one asked for.

WithAuthor now throws ArgumentException naming the value. The check
lives in the builder rather than on GitAuthorName/GitAuthorEmail
because those types also carry identities read back from history.

Fixes #239

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016AQEMQSRnmweax4URvCpi3

Copy link
Copy Markdown
Contributor Author

ci / .NET / Test on macos-latest (job 117521032558) was cancelled after its Test step ran for 54 minutes without finishing. I don't think this change caused it:

GitHub returns 404 for the cancelled job's log, so I can't see which test it stopped in. I'm re-running the cancelled jobs once. If it hangs again, I'll treat the failure as real and look into it on this PR.


Generated by Claude Code

@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 6905ee0 into main Oct 18, 2026
25 of 26 checks passed
@matt-edmondson
matt-edmondson deleted the fix/239-author-ident-characters branch October 18, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commit().WithAuthor() silently records a different author when the name or email contains '<', '>' or a newline

2 participants