Skip to content

Commit 2ac78c7

Browse files
GiteaBotKN4CK3R
andauthored
Include encoding in signature payload (#30174) (#30181)
Backport #30174 by @KN4CK3R Fixes #30119 Include the encoding in the signature payload. before ![grafik](https://github.com/go-gitea/gitea/assets/1666336/01ab94a3-8af5-4d6f-be73-a10b65a15421) after ![grafik](https://github.com/go-gitea/gitea/assets/1666336/3a37d438-c70d-4d69-b178-d170e74aa683) --------- Co-authored-by: KN4CK3R <[email protected]>
1 parent b1dae9f commit 2ac78c7

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

modules/git/commit_convert_gogit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
4747
return nil
4848
}
4949

50+
if c.Encoding != "" && c.Encoding != "UTF-8" {
51+
if _, err = fmt.Fprintf(&w, "\nencoding %s\n", c.Encoding); err != nil {
52+
return nil
53+
}
54+
}
55+
5056
if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
5157
return nil
5258
}

modules/git/commit_reader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ readLoop:
8484
commit.Committer = &Signature{}
8585
commit.Committer.Decode(data)
8686
_, _ = payloadSB.Write(line)
87+
case "encoding":
88+
_, _ = payloadSB.Write(line)
8789
case "gpgsig":
8890
_, _ = signatureSB.Write(data)
8991
_ = signatureSB.WriteByte('\n')

modules/git/commit_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,73 @@ empty commit`, commitFromReader.Signature.Payload)
125125
assert.EqualValues(t, commitFromReader, commitFromReader2)
126126
}
127127

128+
func TestCommitWithEncodingFromReader(t *testing.T) {
129+
commitString := `feaf4ba6bc635fec442f46ddd4512416ec43c2c2 commit 1074
130+
tree ca3fad42080dd1a6d291b75acdfc46e5b9b307e5
131+
parent 47b24e7ab977ed31c5a39989d570847d6d0052af
132+
author KN4CK3R <[email protected]> 1711702962 +0100
133+
committer KN4CK3R <[email protected]> 1711702962 +0100
134+
encoding ISO-8859-1
135+
gpgsig -----BEGIN PGP SIGNATURE-----
136+
137+
iQGzBAABCgAdFiEE9HRrbqvYxPT8PXbefPSEkrowAa8FAmYGg7IACgkQfPSEkrow
138+
Aa9olwv+P0HhtCM6CRvlUmPaqswRsDPNR4i66xyXGiSxdI9V5oJL7HLiQIM7KrFR
139+
gizKa2COiGtugv8fE+TKqXKaJx6uJUJEjaBd8E9Af9PrAzjWj+A84lU6/PgPS8hq
140+
zOfZraLOEWRH4tZcS+u2yFLu3ez2Wqh1xW5LNy7xqEedMXEFD1HwSJ0+pjacNkzr
141+
frp6Asyt7xRI6YmgFJZJoRsS3Ktr6rtKeRL2IErSQQyorOqj6gKrglhrhfG/114j
142+
FKB1v4or0WZ1DE8iP2SJZ3n+/K1IuWAINh7MVdb7PndfBPEa+IL+ucNk5uzEE8Jd
143+
G8smGxXUeFEt2cP1dj2W8EgAxuA9sTnH9dqI5aRqy5ifDjuya7Emm8sdOUvtGdmn
144+
SONRzusmu5n3DgV956REL7x62h7JuqmBz/12HZkr0z0zgXkcZ04q08pSJATX5N1F
145+
yN+tWxTsWg+zhDk96d5Esdo9JMjcFvPv0eioo30GAERaz1hoD7zCMT4jgUFTQwgz
146+
jw4YcO5u
147+
=r3UU
148+
-----END PGP SIGNATURE-----
149+
150+
ISO-8859-1`
151+
152+
sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
153+
gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare"))
154+
assert.NoError(t, err)
155+
assert.NotNil(t, gitRepo)
156+
defer gitRepo.Close()
157+
158+
commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString))
159+
assert.NoError(t, err)
160+
if !assert.NotNil(t, commitFromReader) {
161+
return
162+
}
163+
assert.EqualValues(t, sha, commitFromReader.ID)
164+
assert.EqualValues(t, `-----BEGIN PGP SIGNATURE-----
165+
166+
iQGzBAABCgAdFiEE9HRrbqvYxPT8PXbefPSEkrowAa8FAmYGg7IACgkQfPSEkrow
167+
Aa9olwv+P0HhtCM6CRvlUmPaqswRsDPNR4i66xyXGiSxdI9V5oJL7HLiQIM7KrFR
168+
gizKa2COiGtugv8fE+TKqXKaJx6uJUJEjaBd8E9Af9PrAzjWj+A84lU6/PgPS8hq
169+
zOfZraLOEWRH4tZcS+u2yFLu3ez2Wqh1xW5LNy7xqEedMXEFD1HwSJ0+pjacNkzr
170+
frp6Asyt7xRI6YmgFJZJoRsS3Ktr6rtKeRL2IErSQQyorOqj6gKrglhrhfG/114j
171+
FKB1v4or0WZ1DE8iP2SJZ3n+/K1IuWAINh7MVdb7PndfBPEa+IL+ucNk5uzEE8Jd
172+
G8smGxXUeFEt2cP1dj2W8EgAxuA9sTnH9dqI5aRqy5ifDjuya7Emm8sdOUvtGdmn
173+
SONRzusmu5n3DgV956REL7x62h7JuqmBz/12HZkr0z0zgXkcZ04q08pSJATX5N1F
174+
yN+tWxTsWg+zhDk96d5Esdo9JMjcFvPv0eioo30GAERaz1hoD7zCMT4jgUFTQwgz
175+
jw4YcO5u
176+
=r3UU
177+
-----END PGP SIGNATURE-----
178+
`, commitFromReader.Signature.Signature)
179+
assert.EqualValues(t, `tree ca3fad42080dd1a6d291b75acdfc46e5b9b307e5
180+
parent 47b24e7ab977ed31c5a39989d570847d6d0052af
181+
author KN4CK3R <[email protected]> 1711702962 +0100
182+
committer KN4CK3R <[email protected]> 1711702962 +0100
183+
encoding ISO-8859-1
184+
185+
ISO-8859-1`, commitFromReader.Signature.Payload)
186+
assert.EqualValues(t, "KN4CK3R <[email protected]>", commitFromReader.Author.String())
187+
188+
commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n"))
189+
assert.NoError(t, err)
190+
commitFromReader.CommitMessage += "\n\n"
191+
commitFromReader.Signature.Payload += "\n\n"
192+
assert.EqualValues(t, commitFromReader, commitFromReader2)
193+
}
194+
128195
func TestHasPreviousCommit(t *testing.T) {
129196
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
130197

0 commit comments

Comments
 (0)