Skip to content

Commit 581e52b

Browse files
Relax the version checking for Arch packages (#32908)
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: wxiaoguang <[email protected]>
1 parent 141d782 commit 581e52b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

modules/packages/arch/metadata.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ var (
4343
ErrInvalidArchitecture = util.NewInvalidArgumentErrorf("package architecture is invalid")
4444

4545
// https://man.archlinux.org/man/PKGBUILD.5
46-
namePattern = regexp.MustCompile(`\A[a-zA-Z0-9@._+-]+\z`)
47-
versionPattern = regexp.MustCompile(`\A(?:[0-9]:)?[a-zA-Z0-9.+~]+(?:-[a-zA-Z0-9.+-~]+)?\z`)
46+
namePattern = regexp.MustCompile(`\A[a-zA-Z0-9@._+-]+\z`)
47+
// (epoch:pkgver-pkgrel)
48+
versionPattern = regexp.MustCompile(`\A(?:\d:)?[\w.+~]+(?:-[-\w.+~]+)?\z`)
4849
)
4950

5051
type Package struct {

modules/packages/arch/metadata_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ func TestParsePackageInfo(t *testing.T) {
122122
assert.ErrorIs(t, err, ErrInvalidName)
123123
})
124124

125+
t.Run("Regexp", func(t *testing.T) {
126+
assert.Regexp(t, versionPattern, "1.2_3~4+5")
127+
assert.Regexp(t, versionPattern, "1:2_3~4+5")
128+
assert.NotRegexp(t, versionPattern, "a:1.0.0-1")
129+
assert.NotRegexp(t, versionPattern, "0.0.1/1-1")
130+
assert.NotRegexp(t, versionPattern, "1.0.0 -1")
131+
})
132+
125133
t.Run("InvalidVersion", func(t *testing.T) {
126134
data := createPKGINFOContent(packageName, "")
127135

0 commit comments

Comments
 (0)