Skip to content

Commit

Permalink
Allow non-semver packages in the Conan package registry (go-gitea#20412)
Browse files Browse the repository at this point in the history
A lot of existing packages do not conform to SemVer, yet, they should be allowed
in the Conan package registry as-is. To achieve this, remove the SemVer check
from `NewRecipeReference`, and replace it with a simple empty string check.

A unit test with a non-semver version is also included.

Fixes go-gitea#20405.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
  • Loading branch information
2 people authored and Sysoev, Vladimir committed Aug 10, 2022
1 parent 1940db8 commit 2c389f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/packages/conan/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"errors"
"fmt"
"regexp"
"strings"

"code.gitea.io/gitea/modules/log"

goversion "github.com/hashicorp/go-version"
)

const (
Expand Down Expand Up @@ -56,7 +55,9 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
if !namePattern.MatchString(name) {
return nil, ErrValidation
}
if _, err := goversion.NewSemver(version); err != nil {

v := strings.TrimSpace(version)
if v == "" {
return nil, ErrValidation
}
if user != "" && !namePattern.MatchString(user) {
Expand All @@ -69,7 +70,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
return nil, ErrValidation
}

return &RecipeReference{name, version, user, channel, revision}, nil
return &RecipeReference{name, v, user, channel, revision}, nil
}

func (r *RecipeReference) RevisionOrDefault() string {
Expand Down
1 change: 1 addition & 0 deletions modules/packages/conan/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestNewRecipeReference(t *testing.T) {
{"name", "1.0", "_", "_", "", true},
{"name", "1.0", "_", "_", "0", true},
{"name", "1.0", "", "", "0", true},
{"name", "1.0.0q", "", "", "0", true},
{"name", "1.0", "", "", "000000000000000000000000000000000000000000000000000000000000", false},
}

Expand Down

0 comments on commit 2c389f8

Please sign in to comment.