Skip to content

Commit 93a2d40

Browse files
authored
Merge branch 'main' into fix-repo-topic-edit
2 parents 5e9aa1e + 2dc4f80 commit 93a2d40

File tree

19 files changed

+810
-626
lines changed

19 files changed

+810
-626
lines changed

modules/git/pipeline/revlist.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.
4242
defer revListWriter.Close()
4343
stderr := new(bytes.Buffer)
4444
var errbuf strings.Builder
45-
cmd := git.NewCommand(ctx, "rev-list", "--objects").AddDynamicArguments(headSHA).AddArguments("--not").AddDynamicArguments(baseSHA)
45+
cmd := git.NewCommand(ctx, "rev-list", "--objects").AddDynamicArguments(headSHA)
46+
if baseSHA != "" {
47+
cmd = cmd.AddArguments("--not").AddDynamicArguments(baseSHA)
48+
}
4649
if err := cmd.Run(&git.RunOpts{
4750
Dir: tmpBasePath,
4851
Stdout: revListWriter,

modules/typesniffer/typesniffer.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package typesniffer
55

66
import (
7+
"bytes"
78
"fmt"
89
"io"
910
"net/http"
@@ -24,8 +25,9 @@ const (
2425
)
2526

2627
var (
27-
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
28-
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
28+
svgComment = regexp.MustCompile(`(?s)<!--.*?-->`)
29+
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
30+
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
2931
)
3032

3133
// SniffedType contains information about a blobs type.
@@ -91,10 +93,17 @@ func DetectContentType(data []byte) SniffedType {
9193
data = data[:sniffLen]
9294
}
9395

94-
if (strings.Contains(ct, "text/plain") || strings.Contains(ct, "text/html")) && svgTagRegex.Match(data) ||
95-
strings.Contains(ct, "text/xml") && svgTagInXMLRegex.Match(data) {
96-
// SVG is unsupported. https://github.com/golang/go/issues/15888
97-
ct = SvgMimeType
96+
// SVG is unsupported by http.DetectContentType, https://github.com/golang/go/issues/15888
97+
98+
detectByHTML := strings.Contains(ct, "text/plain") || strings.Contains(ct, "text/html")
99+
detectByXML := strings.Contains(ct, "text/xml")
100+
if detectByHTML || detectByXML {
101+
dataProcessed := svgComment.ReplaceAll(data, nil)
102+
dataProcessed = bytes.TrimSpace(dataProcessed)
103+
if detectByHTML && svgTagRegex.Match(dataProcessed) ||
104+
detectByXML && svgTagInXMLRegex.Match(dataProcessed) {
105+
ct = SvgMimeType
106+
}
98107
}
99108

100109
return SniffedType{ct}

modules/typesniffer/typesniffer_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func TestIsSvgImage(t *testing.T) {
2828
assert.True(t, DetectContentType([]byte("<svg></svg>")).IsSvgImage())
2929
assert.True(t, DetectContentType([]byte(" <svg></svg>")).IsSvgImage())
3030
assert.True(t, DetectContentType([]byte(`<svg width="100"></svg>`)).IsSvgImage())
31-
assert.True(t, DetectContentType([]byte("<svg/>")).IsSvgImage())
3231
assert.True(t, DetectContentType([]byte(`<?xml version="1.0" encoding="UTF-8"?><svg></svg>`)).IsSvgImage())
3332
assert.True(t, DetectContentType([]byte(`<!-- Comment -->
3433
<svg></svg>`)).IsSvgImage())
@@ -57,6 +56,10 @@ func TestIsSvgImage(t *testing.T) {
5756
<!-- Multline
5857
Comment -->
5958
<svg></svg>`)).IsSvgImage())
59+
60+
// the DetectContentType should work for incomplete data, because only beginning bytes are used for detection
61+
assert.True(t, DetectContentType([]byte(`<svg>....`)).IsSvgImage())
62+
6063
assert.False(t, DetectContentType([]byte{}).IsSvgImage())
6164
assert.False(t, DetectContentType([]byte("svg")).IsSvgImage())
6265
assert.False(t, DetectContentType([]byte("<svgfoo></svgfoo>")).IsSvgImage())
@@ -68,6 +71,26 @@ func TestIsSvgImage(t *testing.T) {
6871
assert.False(t, DetectContentType([]byte(`<?xml version="1.0" encoding="UTF-8"?>
6972
<!-- <svg></svg> inside comment -->
7073
<foo></foo>`)).IsSvgImage())
74+
75+
assert.False(t, DetectContentType([]byte(`
76+
<!-- comment1 -->
77+
<div>
78+
<!-- comment2 -->
79+
<svg></svg>
80+
</div>
81+
`)).IsSvgImage())
82+
83+
assert.False(t, DetectContentType([]byte(`
84+
<!-- comment1
85+
-->
86+
<div>
87+
<!-- comment2
88+
-->
89+
<svg></svg>
90+
</div>
91+
`)).IsSvgImage())
92+
assert.False(t, DetectContentType([]byte(`<html><body><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg></body></html>`)).IsSvgImage())
93+
assert.False(t, DetectContentType([]byte(`<html><body><?xml version="1.0" encoding="UTF-8"?><svg></svg></body></html>`)).IsSvgImage())
7194
}
7295

7396
func TestIsPDF(t *testing.T) {

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ default_enable_timetracking_popup=新しいリポジトリのタイムトラッ
247247
no_reply_address=メールを隠すときのドメイン
248248
no_reply_address_helper=メールアドレスを隠しているユーザーに使用するドメイン名。 例えば 'noreply.example.org' と設定した場合、ユーザー名 'joe' はGitに 'joe@noreply.example.org' としてログインすることになります。
249249
password_algorithm=パスワードハッシュアルゴリズム
250+
invalid_password_algorithm=無効なパスワードハッシュアルゴリズム
250251
password_algorithm_helper=パスワードハッシュアルゴリズムを設定します。 アルゴリズムにより動作要件と強度が異なります。 `argon2`は良い特性を備えていますが、多くのメモリを使用するため小さなシステムには適さない場合があります。
251252
enable_update_checker=アップデートチェッカーを有効にする
252253
enable_update_checker_helper=gitea.ioに接続して定期的に新しいバージョンのリリースを確認します。

services/pull/lfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg
116116
}
117117

118118
// Then we need to check that this pointer is in the db
119-
if _, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, pr.HeadRepo.ID, pointer.Oid); err != nil {
119+
if _, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, pr.HeadRepoID, pointer.Oid); err != nil {
120120
if err == git_model.ErrLFSObjectNotExist {
121121
log.Warn("During merge of: %d in %-v, there is a pointer to LFS Oid: %s which although present in the LFS store is not associated with the head repo %-v", pr.Index, pr.BaseRepo, pointer.Oid, pr.HeadRepo)
122122
continue

0 commit comments

Comments
 (0)