aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-07-14 11:39:15 +0200
committerGitHub <noreply@github.com>2023-07-14 09:39:15 +0000
commitbd82d8974e84eeff8072c962c7253db3f4128f69 (patch)
treeced9fba1fc79a530167f94fa9f58fe2e7f3028c2 /modules
parentdc679fc9faf3c661d23849f3cc1c3e02f995f74f (diff)
downloadgitea-bd82d8974e84eeff8072c962c7253db3f4128f69.tar.gz
gitea-bd82d8974e84eeff8072c962c7253db3f4128f69.zip
Add support for different Maven POM encoding (#25873)
Fixes #25853 - Maven POM files aren't always UTF-8 encoded. - Reject the upload of unparsable POM files
Diffstat (limited to 'modules')
-rw-r--r--modules/packages/maven/metadata.go7
-rw-r--r--modules/packages/maven/metadata_test.go17
2 files changed, 23 insertions, 1 deletions
diff --git a/modules/packages/maven/metadata.go b/modules/packages/maven/metadata.go
index be057c8c07..42aa250718 100644
--- a/modules/packages/maven/metadata.go
+++ b/modules/packages/maven/metadata.go
@@ -8,6 +8,8 @@ import (
"io"
"code.gitea.io/gitea/modules/validation"
+
+ "golang.org/x/net/html/charset"
)
// Metadata represents the metadata of a Maven package
@@ -52,7 +54,10 @@ type pomStruct struct {
// ParsePackageMetaData parses the metadata of a pom file
func ParsePackageMetaData(r io.Reader) (*Metadata, error) {
var pom pomStruct
- if err := xml.NewDecoder(r).Decode(&pom); err != nil {
+
+ dec := xml.NewDecoder(r)
+ dec.CharsetReader = charset.NewReaderLabel
+ if err := dec.Decode(&pom); err != nil {
return nil, err
}
diff --git a/modules/packages/maven/metadata_test.go b/modules/packages/maven/metadata_test.go
index f4bc84268e..e675467730 100644
--- a/modules/packages/maven/metadata_test.go
+++ b/modules/packages/maven/metadata_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "golang.org/x/text/encoding/charmap"
)
const (
@@ -69,4 +70,20 @@ func TestParsePackageMetaData(t *testing.T) {
assert.Equal(t, dependencyArtifactID, m.Dependencies[0].ArtifactID)
assert.Equal(t, dependencyVersion, m.Dependencies[0].Version)
})
+
+ t.Run("Encoding", func(t *testing.T) {
+ // UTF-8 is default but the metadata could be encoded differently
+ pomContent8859_1, err := charmap.ISO8859_1.NewEncoder().String(
+ strings.ReplaceAll(
+ pomContent,
+ `<?xml version="1.0"?>`,
+ `<?xml version="1.0" encoding="ISO-8859-1"?>`,
+ ),
+ )
+ assert.NoError(t, err)
+
+ m, err := ParsePackageMetaData(strings.NewReader(pomContent8859_1))
+ assert.NoError(t, err)
+ assert.NotNil(t, m)
+ })
}