Skip to content

Commit 61a9b6c

Browse files
authored
Merge branch 'release/v1.23' into backport-32974-v1.23
2 parents 54ebb7f + af5e5e8 commit 61a9b6c

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

modules/packages/maven/metadata.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/xml"
88
"io"
99

10+
"code.gitea.io/gitea/modules/util"
1011
"code.gitea.io/gitea/modules/validation"
1112

1213
"golang.org/x/net/html/charset"
@@ -31,18 +32,27 @@ type Dependency struct {
3132
}
3233

3334
type pomStruct struct {
34-
XMLName xml.Name `xml:"project"`
35-
GroupID string `xml:"groupId"`
36-
ArtifactID string `xml:"artifactId"`
37-
Version string `xml:"version"`
38-
Name string `xml:"name"`
39-
Description string `xml:"description"`
40-
URL string `xml:"url"`
41-
Licenses []struct {
35+
XMLName xml.Name `xml:"project"`
36+
37+
Parent struct {
38+
GroupID string `xml:"groupId"`
39+
ArtifactID string `xml:"artifactId"`
40+
Version string `xml:"version"`
41+
} `xml:"parent"`
42+
43+
GroupID string `xml:"groupId"`
44+
ArtifactID string `xml:"artifactId"`
45+
Version string `xml:"version"`
46+
Name string `xml:"name"`
47+
Description string `xml:"description"`
48+
URL string `xml:"url"`
49+
50+
Licenses []struct {
4251
Name string `xml:"name"`
4352
URL string `xml:"url"`
4453
Distribution string `xml:"distribution"`
4554
} `xml:"licenses>license"`
55+
4656
Dependencies []struct {
4757
GroupID string `xml:"groupId"`
4858
ArtifactID string `xml:"artifactId"`
@@ -81,8 +91,16 @@ func ParsePackageMetaData(r io.Reader) (*Metadata, error) {
8191
})
8292
}
8393

94+
pomGroupID := pom.GroupID
95+
if pomGroupID == "" {
96+
// the current module could inherit parent: https://maven.apache.org/pom.html#Inheritance
97+
pomGroupID = pom.Parent.GroupID
98+
}
99+
if pomGroupID == "" {
100+
return nil, util.ErrInvalidArgument
101+
}
84102
return &Metadata{
85-
GroupID: pom.GroupID,
103+
GroupID: pomGroupID,
86104
ArtifactID: pom.ArtifactID,
87105
Name: pom.Name,
88106
Description: pom.Description,

modules/packages/maven/metadata_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"strings"
88
"testing"
99

10+
"code.gitea.io/gitea/modules/util"
11+
1012
"github.com/stretchr/testify/assert"
13+
"github.com/stretchr/testify/require"
1114
"golang.org/x/text/encoding/charmap"
1215
)
1316

@@ -86,4 +89,35 @@ func TestParsePackageMetaData(t *testing.T) {
8689
assert.NoError(t, err)
8790
assert.NotNil(t, m)
8891
})
92+
93+
t.Run("ParentInherit", func(t *testing.T) {
94+
pom := `<?xml version="1.0"?>
95+
<project>
96+
<modelVersion>4.0.0</modelVersion>
97+
<parent>
98+
<groupId>com.mycompany.app</groupId>
99+
<artifactId>my-app</artifactId>
100+
<version>1.0-SNAPSHOT</version>
101+
</parent>
102+
<artifactId>submodule1</artifactId>
103+
</project>
104+
`
105+
m, err := ParsePackageMetaData(strings.NewReader(pom))
106+
require.NoError(t, err)
107+
require.NotNil(t, m)
108+
109+
assert.Equal(t, "com.mycompany.app", m.GroupID)
110+
assert.Equal(t, "submodule1", m.ArtifactID)
111+
})
112+
113+
t.Run("ParentInherit", func(t *testing.T) {
114+
pom := `<?xml version="1.0"?>
115+
<project>
116+
<modelVersion>4.0.0</modelVersion>
117+
<artifactId></artifactId>
118+
</project>
119+
`
120+
_, err := ParsePackageMetaData(strings.NewReader(pom))
121+
require.ErrorIs(t, err, util.ErrInvalidArgument)
122+
})
89123
}

routers/api/packages/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ func CommonRoutes() *web.Router {
465465
r.Post("/api/charts", reqPackageAccess(perm.AccessModeWrite), helm.UploadPackage)
466466
}, reqPackageAccess(perm.AccessModeRead))
467467
r.Group("/maven", func() {
468+
// FIXME: this path design is not right.
469+
// It should be `/.../{groupId}/{artifactId}/{version}`, but not `/.../{groupId}-{artifactId}/{version}`
468470
r.Put("/*", reqPackageAccess(perm.AccessModeWrite), maven.UploadPackageFile)
469471
r.Get("/*", maven.DownloadPackageFile)
470472
r.Head("/*", maven.ProvidePackageFileHeader)

web_src/js/features/comp/EditorMarkdown.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,36 @@ test('EditorMarkdown', () => {
44
const textarea = document.createElement('textarea');
55
initTextareaMarkdown(textarea);
66

7-
const testInput = (value, expected) => {
8-
textarea.value = value;
9-
textarea.setSelectionRange(value.length, value.length);
7+
type ValueWithCursor = string | {
8+
value: string;
9+
pos: number;
10+
}
11+
const testInput = (input: ValueWithCursor, result: ValueWithCursor) => {
12+
const intputValue = typeof input === 'string' ? input : input.value;
13+
const inputPos = typeof input === 'string' ? intputValue.length : input.pos;
14+
textarea.value = intputValue;
15+
textarea.setSelectionRange(inputPos, inputPos);
16+
1017
const e = new KeyboardEvent('keydown', {key: 'Enter', cancelable: true});
1118
textarea.dispatchEvent(e);
12-
if (!e.defaultPrevented) textarea.value += '\n';
13-
expect(textarea.value).toEqual(expected);
19+
if (!e.defaultPrevented) textarea.value += '\n'; // simulate default behavior
20+
21+
const expectedValue = typeof result === 'string' ? result : result.value;
22+
const expectedPos = typeof result === 'string' ? expectedValue.length : result.pos;
23+
expect(textarea.value).toEqual(expectedValue);
24+
expect(textarea.selectionStart).toEqual(expectedPos);
1425
};
1526

1627
testInput('-', '-\n');
1728
testInput('1.', '1.\n');
1829

1930
testInput('- ', '');
2031
testInput('1. ', '');
32+
testInput({value: '1. \n2. ', pos: 3}, {value: '\n2. ', pos: 0});
2133

2234
testInput('- x', '- x\n- ');
35+
testInput('1. foo', '1. foo\n1. ');
36+
testInput({value: '1. a\n2. b\n3. c', pos: 4}, {value: '1. a\n1. \n2. b\n3. c', pos: 8});
2337
testInput('- [ ]', '- [ ]\n- ');
2438
testInput('- [ ] foo', '- [ ] foo\n- [ ] ');
2539
testInput('* [x] foo', '* [x] foo\n* [ ] ');

web_src/js/features/comp/EditorMarkdown.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function handleNewline(textarea: HTMLTextAreaElement, e: Event) {
9292
if (!line) {
9393
// clear current line if we only have i.e. '1. ' and the user presses enter again to finish creating a list
9494
textarea.value = value.slice(0, lineStart) + value.slice(lineEnd);
95+
textarea.setSelectionRange(selStart - prefix.length, selStart - prefix.length);
9596
} else {
9697
// start a new line with the same indention and prefix
9798
let newPrefix = prefix;

0 commit comments

Comments
 (0)