aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-12-19 19:02:58 +0800
committerGitHub <noreply@github.com>2024-12-19 19:02:58 +0800
commitc20642fa9936c00e1277896152a0f73d89e3de4b (patch)
tree2210c5ead8c6b3ff4ad5581a02efd6e4831e2474 /modules
parenta4291fd55378ee73dbda70a19b93764e8c547377 (diff)
downloadgitea-c20642fa9936c00e1277896152a0f73d89e3de4b.tar.gz
gitea-c20642fa9936c00e1277896152a0f73d89e3de4b.zip
Relax the version checking for Arch packages (#32908) (#32913)
Backport #32908 by ExplodingDragon It is mentioned in https://man.archlinux.org/man/PKGBUILD.5: 'The variable is not allowed to contain colons, forward slashes, hyphens, or whitespace.' `_` is also an allowed character, and some software in the Arch Linux AUR uses this naming convention. Co-authored-by: Exploding Dragon <explodingfkl@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/packages/arch/metadata.go5
-rw-r--r--modules/packages/arch/metadata_test.go8
2 files changed, 11 insertions, 2 deletions
diff --git a/modules/packages/arch/metadata.go b/modules/packages/arch/metadata.go
index 06a2206a36..3d7bdf3997 100644
--- a/modules/packages/arch/metadata.go
+++ b/modules/packages/arch/metadata.go
@@ -43,8 +43,9 @@ var (
ErrInvalidArchitecture = util.NewInvalidArgumentErrorf("package architecture is invalid")
// https://man.archlinux.org/man/PKGBUILD.5
- namePattern = regexp.MustCompile(`\A[a-zA-Z0-9@._+-]+\z`)
- versionPattern = regexp.MustCompile(`\A(?:[0-9]:)?[a-zA-Z0-9.+~]+(?:-[a-zA-Z0-9.+-~]+)?\z`)
+ namePattern = regexp.MustCompile(`\A[a-zA-Z0-9@._+-]+\z`)
+ // (epoch:pkgver-pkgrel)
+ versionPattern = regexp.MustCompile(`\A(?:\d:)?[\w.+~]+(?:-[-\w.+~]+)?\z`)
)
type Package struct {
diff --git a/modules/packages/arch/metadata_test.go b/modules/packages/arch/metadata_test.go
index 37c0a553b8..5bdf63a3ee 100644
--- a/modules/packages/arch/metadata_test.go
+++ b/modules/packages/arch/metadata_test.go
@@ -122,6 +122,14 @@ func TestParsePackageInfo(t *testing.T) {
assert.ErrorIs(t, err, ErrInvalidName)
})
+ t.Run("Regexp", func(t *testing.T) {
+ assert.Regexp(t, versionPattern, "1.2_3~4+5")
+ assert.Regexp(t, versionPattern, "1:2_3~4+5")
+ assert.NotRegexp(t, versionPattern, "a:1.0.0-1")
+ assert.NotRegexp(t, versionPattern, "0.0.1/1-1")
+ assert.NotRegexp(t, versionPattern, "1.0.0 -1")
+ })
+
t.Run("InvalidVersion", func(t *testing.T) {
data := createPKGINFOContent(packageName, "")