Skip to content

Commit b70cbe8

Browse files
authored
Merge branch 'master' into fix-spelling
2 parents d82b48c + 27fa481 commit b70cbe8

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

integrations/api_repo_git_tags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestAPIGitTags(t *testing.T) {
5050
assert.Equal(t, aTagName, tag.Tag)
5151
assert.Equal(t, aTag.ID.String(), tag.SHA)
5252
assert.Equal(t, commit.ID.String(), tag.Object.SHA)
53-
assert.Equal(t, aTagMessage, tag.Message)
53+
assert.Equal(t, aTagMessage+"\n", tag.Message)
5454
assert.Equal(t, user.Name, tag.Tagger.Name)
5555
assert.Equal(t, user.Email, tag.Tagger.Email)
5656
assert.Equal(t, util.URLJoin(repo.APIURL(), "git/tags", aTag.ID.String()), tag.URL)

modules/git/repo_tree_nogogit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
3333

3434
bufReader := bufio.NewReader(stdoutReader)
3535
// ignore the SHA
36-
_, typ, _, err := ReadBatchLine(bufReader)
36+
_, typ, size, err := ReadBatchLine(bufReader)
3737
if err != nil {
3838
return nil, err
3939
}
4040

4141
switch typ {
4242
case "tag":
4343
resolvedID := id
44-
data, err := ioutil.ReadAll(bufReader)
44+
data, err := ioutil.ReadAll(io.LimitReader(bufReader, size))
4545
if err != nil {
4646
return nil, err
4747
}
@@ -57,7 +57,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
5757
log("tag.commit.Tree: %s %v", commit.Tree.ID.String(), commit.Tree.repo)
5858
return &commit.Tree, nil
5959
case "commit":
60-
commit, err := CommitFromReader(repo, id, bufReader)
60+
commit, err := CommitFromReader(repo, id, io.LimitReader(bufReader, size))
6161
if err != nil {
6262
_ = stdoutReader.CloseWithError(err)
6363
return nil, err

modules/git/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ l:
6464
}
6565
nextline += eol + 1
6666
case eol == 0:
67-
tag.Message = string(data[nextline+1 : len(data)-1])
67+
tag.Message = string(data[nextline+1:])
6868
break l
6969
default:
7070
break l

modules/git/tag_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func Test_parseTagData(t *testing.T) {
15+
testData := []struct {
16+
data []byte
17+
tag Tag
18+
}{
19+
{data: []byte(`object 3b114ab800c6432ad42387ccf6bc8d4388a2885a
20+
type commit
21+
tag 1.22.0
22+
tagger Lucas Michot <[email protected]> 1484491741 +0100
23+
24+
`), tag: Tag{
25+
Name: "",
26+
ID: SHA1{},
27+
repo: nil,
28+
Object: SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a},
29+
Type: "commit",
30+
Tagger: &Signature{Name: "Lucas Michot", Email: "[email protected]", When: time.Unix(1484491741, 0)},
31+
Message: "",
32+
Signature: nil,
33+
}},
34+
{data: []byte(`object 7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc
35+
type commit
36+
tag 1.22.1
37+
tagger Lucas Michot <[email protected]> 1484553735 +0100
38+
39+
test message
40+
o
41+
42+
ono`), tag: Tag{
43+
Name: "",
44+
ID: SHA1{},
45+
repo: nil,
46+
Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc},
47+
Type: "commit",
48+
Tagger: &Signature{Name: "Lucas Michot", Email: "[email protected]", When: time.Unix(1484553735, 0)},
49+
Message: "test message\no\n\nono",
50+
Signature: nil,
51+
}},
52+
}
53+
54+
for _, test := range testData {
55+
tag, err := parseTagData(test.data)
56+
assert.NoError(t, err)
57+
assert.EqualValues(t, test.tag.ID, tag.ID)
58+
assert.EqualValues(t, test.tag.Object, tag.Object)
59+
assert.EqualValues(t, test.tag.Name, tag.Name)
60+
assert.EqualValues(t, test.tag.Message, tag.Message)
61+
assert.EqualValues(t, test.tag.Type, tag.Type)
62+
if test.tag.Signature != nil && assert.NotNil(t, tag.Signature) {
63+
assert.EqualValues(t, test.tag.Signature.Signature, tag.Signature.Signature)
64+
assert.EqualValues(t, test.tag.Signature.Payload, tag.Signature.Payload)
65+
} else {
66+
assert.Nil(t, tag.Signature)
67+
}
68+
if test.tag.Tagger != nil && assert.NotNil(t, tag.Tagger) {
69+
assert.EqualValues(t, test.tag.Tagger.Name, tag.Tagger.Name)
70+
assert.EqualValues(t, test.tag.Tagger.Email, tag.Tagger.Email)
71+
assert.EqualValues(t, test.tag.Tagger.When.Unix(), tag.Tagger.When.Unix())
72+
} else {
73+
assert.Nil(t, tag.Tagger)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)