From e16b9ef0786d0a1da351499a2789d322aa34280f Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 19 Jul 2022 20:39:42 +0200 Subject: [PATCH 1/4] Allow non-semver packages in the Conan package registry 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 #20405. Signed-off-by: Gergely Nagy --- modules/packages/conan/reference.go | 4 +--- modules/packages/conan/reference_test.go | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/packages/conan/reference.go b/modules/packages/conan/reference.go index c43446e6e5bda..06428ec4d24f0 100644 --- a/modules/packages/conan/reference.go +++ b/modules/packages/conan/reference.go @@ -10,8 +10,6 @@ import ( "regexp" "code.gitea.io/gitea/modules/log" - - goversion "github.com/hashicorp/go-version" ) const ( @@ -56,7 +54,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR if !namePattern.MatchString(name) { return nil, ErrValidation } - if _, err := goversion.NewSemver(version); err != nil { + if (version == "") { return nil, ErrValidation } if user != "" && !namePattern.MatchString(user) { diff --git a/modules/packages/conan/reference_test.go b/modules/packages/conan/reference_test.go index 29ba3a543bf2d..98eb2c847843d 100644 --- a/modules/packages/conan/reference_test.go +++ b/modules/packages/conan/reference_test.go @@ -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}, } From 6d0b446b563c99ad09495377cf7eed8ef5953a33 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 19 Jul 2022 20:54:28 +0200 Subject: [PATCH 2/4] Update modules/packages/conan/reference.go --- modules/packages/conan/reference.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/packages/conan/reference.go b/modules/packages/conan/reference.go index 06428ec4d24f0..6851202a5e912 100644 --- a/modules/packages/conan/reference.go +++ b/modules/packages/conan/reference.go @@ -54,7 +54,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR if !namePattern.MatchString(name) { return nil, ErrValidation } - if (version == "") { + if version == "" { return nil, ErrValidation } if user != "" && !namePattern.MatchString(user) { From 802d73d2fe397b2dc3cc7557ad8bfaafceb4ba4b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 20 Jul 2022 16:59:16 +0200 Subject: [PATCH 3/4] Update modules/packages/conan/reference.go Co-authored-by: KN4CK3R --- modules/packages/conan/reference.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/packages/conan/reference.go b/modules/packages/conan/reference.go index 6851202a5e912..da3a213ed0672 100644 --- a/modules/packages/conan/reference.go +++ b/modules/packages/conan/reference.go @@ -54,7 +54,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR if !namePattern.MatchString(name) { return nil, ErrValidation } - if version == "" { + if strings.TrimSpace(version) == "" { return nil, ErrValidation } if user != "" && !namePattern.MatchString(user) { From a7fbb1eff71fab517bdb4e08d33f60ac35ff79de Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 21 Jul 2022 19:16:14 +0200 Subject: [PATCH 4/4] packages/conan: Use the whitespace-trimmed version Instead of just checking whether the version is all-whitespace (or empty), use the trimmed version down the line, too. Also import "strings", since we're using its TrimSpace method. Signed-off-by: Gergely Nagy --- modules/packages/conan/reference.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/packages/conan/reference.go b/modules/packages/conan/reference.go index da3a213ed0672..49236981b67f8 100644 --- a/modules/packages/conan/reference.go +++ b/modules/packages/conan/reference.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "regexp" + "strings" "code.gitea.io/gitea/modules/log" ) @@ -54,7 +55,9 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR if !namePattern.MatchString(name) { return nil, ErrValidation } - if strings.TrimSpace(version) == "" { + + v := strings.TrimSpace(version) + if v == "" { return nil, ErrValidation } if user != "" && !namePattern.MatchString(user) { @@ -67,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 {