Skip to content

Commit dc34ea2

Browse files
authored
Merge branch 'release/v1.20' into backport-25733-v1.20
2 parents 1d6ae04 + 186f07b commit dc34ea2

File tree

9 files changed

+46
-14
lines changed

9 files changed

+46
-14
lines changed

modules/packages/maven/metadata.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"io"
99

1010
"code.gitea.io/gitea/modules/validation"
11+
12+
"golang.org/x/net/html/charset"
1113
)
1214

1315
// Metadata represents the metadata of a Maven package
@@ -52,7 +54,10 @@ type pomStruct struct {
5254
// ParsePackageMetaData parses the metadata of a pom file
5355
func ParsePackageMetaData(r io.Reader) (*Metadata, error) {
5456
var pom pomStruct
55-
if err := xml.NewDecoder(r).Decode(&pom); err != nil {
57+
58+
dec := xml.NewDecoder(r)
59+
dec.CharsetReader = charset.NewReaderLabel
60+
if err := dec.Decode(&pom); err != nil {
5661
return nil, err
5762
}
5863

modules/packages/maven/metadata_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/stretchr/testify/assert"
11+
"golang.org/x/text/encoding/charmap"
1112
)
1213

1314
const (
@@ -69,4 +70,20 @@ func TestParsePackageMetaData(t *testing.T) {
6970
assert.Equal(t, dependencyArtifactID, m.Dependencies[0].ArtifactID)
7071
assert.Equal(t, dependencyVersion, m.Dependencies[0].Version)
7172
})
73+
74+
t.Run("Encoding", func(t *testing.T) {
75+
// UTF-8 is default but the metadata could be encoded differently
76+
pomContent8859_1, err := charmap.ISO8859_1.NewEncoder().String(
77+
strings.ReplaceAll(
78+
pomContent,
79+
`<?xml version="1.0"?>`,
80+
`<?xml version="1.0" encoding="ISO-8859-1"?>`,
81+
),
82+
)
83+
assert.NoError(t, err)
84+
85+
m, err := ParsePackageMetaData(strings.NewReader(pomContent8859_1))
86+
assert.NoError(t, err)
87+
assert.NotNil(t, m)
88+
})
7289
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,7 @@ diff.show_more = Show More
23662366
diff.load = Load Diff
23672367
diff.generated = generated
23682368
diff.vendored = vendored
2369+
diff.comment.add_line_comment = Add line comment
23692370
diff.comment.placeholder = Leave a comment
23702371
diff.comment.markdown_info = Styling with markdown is supported.
23712372
diff.comment.add_single_comment = Add single comment

routers/api/packages/maven/maven.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ var (
4949

5050
func apiError(ctx *context.Context, status int, obj any) {
5151
helper.LogAndProcessError(ctx, status, obj, func(message string) {
52+
// The maven client does not present the error message to the user. Log it for users with access to server logs.
53+
if status == http.StatusBadRequest || status == http.StatusInternalServerError {
54+
log.Error(message)
55+
}
56+
5257
ctx.PlainText(status, message)
5358
})
5459
}
@@ -326,7 +331,8 @@ func UploadPackageFile(ctx *context.Context) {
326331
var err error
327332
pvci.Metadata, err = maven_module.ParsePackageMetaData(buf)
328333
if err != nil {
329-
log.Error("Error parsing package metadata: %v", err)
334+
apiError(ctx, http.StatusBadRequest, err)
335+
return
330336
}
331337

332338
if pvci.Metadata != nil {

routers/web/repo/release.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
196196
}
197197

198198
ctx.Data["Releases"] = releases
199-
ctx.Data["ReleasesNum"] = len(releases)
200199

201200
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
202201
pager.SetDefaultParams(ctx)

templates/repo/diff/section_split.tmpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
<td class="lines-type-marker lines-type-marker-old del-code"><span class="gt-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
4848
<td class="lines-code lines-code-old del-code">{{/*
4949
*/}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/*
50-
*/}}<a class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{/*
50+
*/}}<button type="button" aria-label="{{$.root.locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{/*
5151
*/}}{{svg "octicon-plus"}}{{/*
52-
*/}}</a>{{/*
52+
*/}}</button>{{/*
5353
*/}}{{end}}{{/*
5454
*/}}{{if $line.LeftIdx}}{{/*
5555
*/}}{{template "repo/diff/section_code" dict "diff" $leftDiff "locale" $.root.locale}}{{/*
@@ -62,9 +62,9 @@
6262
<td class="lines-type-marker lines-type-marker-new add-code">{{if $match.RightIdx}}<span class="gt-mono" data-type-marker="{{$match.GetLineTypeMarker}}"></span>{{end}}</td>
6363
<td class="lines-code lines-code-new add-code">{{/*
6464
*/}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/*
65-
*/}}<a class="ui primary button add-code-comment add-code-comment-right{{if (not $match.CanComment)}} invisible{{end}}" data-side="right" data-idx="{{$match.RightIdx}}">{{/*
65+
*/}}<button type="button" aria-label="{{$.root.locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-right{{if (not $match.CanComment)}} invisible{{end}}" data-side="right" data-idx="{{$match.RightIdx}}">{{/*
6666
*/}}{{svg "octicon-plus"}}{{/*
67-
*/}}</a>{{/*
67+
*/}}</button>{{/*
6868
*/}}{{end}}{{/*
6969
*/}}{{if $match.RightIdx}}{{/*
7070
*/}}{{template "repo/diff/section_code" dict "diff" $rightDiff "locale" $.root.locale}}{{/*
@@ -79,9 +79,9 @@
7979
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="gt-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
8080
<td class="lines-code lines-code-old">{{/*
8181
*/}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2))}}{{/*
82-
*/}}<a class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{/*
82+
*/}}<button type="button" aria-label="{{$.root.locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{/*
8383
*/}}{{svg "octicon-plus"}}{{/*
84-
*/}}</a>{{/*
84+
*/}}</button>{{/*
8585
*/}}{{end}}{{/*
8686
*/}}{{if $line.LeftIdx}}{{/*
8787
*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/*
@@ -94,9 +94,9 @@
9494
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="gt-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
9595
<td class="lines-code lines-code-new">{{/*
9696
*/}}{{if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3))}}{{/*
97-
*/}}<a class="ui primary button add-code-comment add-code-comment-right{{if (not $line.CanComment)}} invisible{{end}}" data-side="right" data-idx="{{$line.RightIdx}}">{{/*
97+
*/}}<button type="button" aria-label="{{$.root.locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-right{{if (not $line.CanComment)}} invisible{{end}}" data-side="right" data-idx="{{$line.RightIdx}}">{{/*
9898
*/}}{{svg "octicon-plus"}}{{/*
99-
*/}}</a>{{/*
99+
*/}}</button>{{/*
100100
*/}}{{end}}{{/*
101101
*/}}{{if $line.RightIdx}}{{/*
102102
*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/*

templates/repo/diff/section_unified.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
{{else}}
5353
<td class="chroma lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}">{{/*
5454
*/}}{{if and $.root.SignedUserID $.root.PageIsPullFiles}}{{/*
55-
*/}}<a class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
55+
*/}}<button type="button" aria-label="{{$.root.locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
5656
*/}}{{svg "octicon-plus"}}{{/*
57-
*/}}</a>{{/*
57+
*/}}</button>{{/*
5858
*/}}{{end}}{{/*
5959
*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff "locale" $.root.locale}}{{/*
6060
*/}}</td>

templates/repo/release_tag_header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="gt-df">
66
<div class="gt-f1 gt-df gt-ac">
77
<h2 class="ui compact small menu header small-menu-items">
8-
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.PrettyNumber .ReleasesNum}} {{.locale.TrN .ReleasesNum "repo.release" "repo.releases"}}</a>
8+
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.PrettyNumber .NumReleases}} {{.locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
99
{{if $canReadCode}}
1010
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.PrettyNumber .NumTags}} {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
1111
{{end}}

web_src/css/review.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
opacity: 1;
3737
}
3838

39+
.ui.button.add-code-comment:focus {
40+
opacity: 1;
41+
}
42+
3943
.repository .diff-file-box .code-diff .add-comment-left,
4044
.repository .diff-file-box .code-diff .add-comment-right,
4145
.repository .diff-file-box .code-diff .add-code-comment .add-comment-left,

0 commit comments

Comments
 (0)