fix(commit): trim all trailing whitespace from signature names
- commit
- 5228465d7a80374c8b4a6261aa7ac49da53ff641
- author
- brice · · 2026-10-11 01:07 UTC
- parent
- 585a2d1
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email - refs
- tag: v0.1.0
2 files · +23 -1
M commit.go +1 -1
| @@ -140,7 +140,7 @@ func parseSignature(b []byte) Signature { | |||
| 140 | 140 | s.Name = bytes.TrimSpace(b) | |
| 141 | 141 | return s | |
| 142 | 142 | } | |
| 143 | - | s.Name = bytes.TrimRight(b[:lt], " ") | |
| 143 | + | s.Name = bytes.TrimRight(b[:lt], " \t\r\n") | |
| 144 | 144 | s.Email = b[lt+1 : gt] | |
| 145 | 145 | rest := bytes.TrimLeft(b[gt+1:], " ") | |
| 146 | 146 | secs, rest, _ := bytes.Cut(rest, []byte{' '}) | |
| @@ -140,7 +140,7 @@ func parseSignature(b []byte) Signature { | |||||
| 140 | s.Name = bytes.TrimSpace(b) | 140 | s.Name = bytes.TrimSpace(b) | ||
| 141 | return s | 141 | return s | ||
| 142 | } | 142 | } | ||
| 143 | - | s.Name = bytes.TrimRight(b[:lt], " ") | 143 | + | s.Name = bytes.TrimRight(b[:lt], " \t\r\n") |
| 144 | s.Email = b[lt+1 : gt] | 144 | s.Email = b[lt+1 : gt] | ||
| 145 | rest := bytes.TrimLeft(b[gt+1:], " ") | 145 | rest := bytes.TrimLeft(b[gt+1:], " ") | ||
| 146 | secs, rest, _ := bytes.Cut(rest, []byte{' '}) | 146 | secs, rest, _ := bytes.Cut(rest, []byte{' '}) | ||
M conformance_test.go +22 -0
| @@ -818,3 +818,25 @@ func TestConformanceDeltaCacheSizes(t *testing.T) { | |||
| 818 | 818 | }) | |
| 819 | 819 | } | |
| 820 | 820 | } | |
| 821 | + | ||
| 822 | + | // The name of a signature loses all its trailing whitespace, as in git's | |
| 823 | + | // split_ident_line (%an), not only spaces. | |
| 824 | + | func TestSignatureNameTrimming(t *testing.T) { | |
| 825 | + | f := newFx(t) | |
| 826 | + | f.write("f", []byte("x\n"), 0o644) | |
| 827 | + | f.commit("one") | |
| 828 | + | tree := f.git("rev-parse", "HEAD^{tree}") | |
| 829 | + | for _, name := range []string{"A B", "A \t\r ", "A\t", "A\r", "A \t B \t", "\tlead \t", "A\v", "A\f", " "} { | |
| 830 | + | raw := "tree " + tree + "\nauthor " + name + "<a@b.c> 1700000000 +0100\ncommitter x <a@b.c> 1700000000 +0100\n\nm\n" | |
| 831 | + | id := f.gitIn([]byte(raw), "hash-object", "-t", "commit", "-w", "--literally", "--stdin") | |
| 832 | + | want := string(runGit(t, f.root(), nil, f.env(), "log", "-1", "--format=%an", id)) | |
| 833 | + | want = strings.TrimSuffix(want, "\n") | |
| 834 | + | var c Commit | |
| 835 | + | if err := f.open().ReadCommit(mustID(t, id), &c); err != nil { | |
| 836 | + | t.Fatal(err) | |
| 837 | + | } | |
| 838 | + | if string(c.Author.Name) != want { | |
| 839 | + | t.Errorf("author %q: name %q, git %%an %q", name, c.Author.Name, want) | |
| 840 | + | } | |
| 841 | + | } | |
| 842 | + | } | |
| @@ -818,3 +818,25 @@ func TestConformanceDeltaCacheSizes(t *testing.T) { | |||||
| 818 | }) | 818 | }) | ||
| 819 | } | 819 | } | ||
| 820 | } | 820 | } | ||
| 821 | + | ||||
| 822 | + | // The name of a signature loses all its trailing whitespace, as in git's | |||
| 823 | + | // split_ident_line (%an), not only spaces. | |||
| 824 | + | func TestSignatureNameTrimming(t *testing.T) { | |||
| 825 | + | f := newFx(t) | |||
| 826 | + | f.write("f", []byte("x\n"), 0o644) | |||
| 827 | + | f.commit("one") | |||
| 828 | + | tree := f.git("rev-parse", "HEAD^{tree}") | |||
| 829 | + | for _, name := range []string{"A B", "A \t\r ", "A\t", "A\r", "A \t B \t", "\tlead \t", "A\v", "A\f", " "} { | |||
| 830 | + | raw := "tree " + tree + "\nauthor " + name + "<a@b.c> 1700000000 +0100\ncommitter x <a@b.c> 1700000000 +0100\n\nm\n" | |||
| 831 | + | id := f.gitIn([]byte(raw), "hash-object", "-t", "commit", "-w", "--literally", "--stdin") | |||
| 832 | + | want := string(runGit(t, f.root(), nil, f.env(), "log", "-1", "--format=%an", id)) | |||
| 833 | + | want = strings.TrimSuffix(want, "\n") | |||
| 834 | + | var c Commit | |||
| 835 | + | if err := f.open().ReadCommit(mustID(t, id), &c); err != nil { | |||
| 836 | + | t.Fatal(err) | |||
| 837 | + | } | |||
| 838 | + | if string(c.Author.Name) != want { | |||
| 839 | + | t.Errorf("author %q: name %q, git %%an %q", name, c.Author.Name, want) | |||
| 840 | + | } | |||
| 841 | + | } | |||
| 842 | + | } | |||