Skip to content

Commit

Permalink
Relax the version checking for Arch packages (#32908)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ExplodingDragon and wxiaoguang authored Dec 19, 2024
1 parent 141d782 commit 581e52b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/packages/arch/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions modules/packages/arch/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")

Expand Down

0 comments on commit 581e52b

Please sign in to comment.