Skip to content

packages/generic: Do not restrict package versions to SemVer #20414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 28, 2022
Merged
2 changes: 1 addition & 1 deletion docs/content/doc/packages/generic.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PUT https://gitea.example.com/api/packages/{owner}/generic/{package_name}/{packa
| ----------------- | ----------- |
| `owner` | The owner of the package. |
| `package_name` | The package name. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`). |
| `package_version` | The package version as described in the [SemVer](https://semver.org/) spec. |
| `package_version` | The package version, a non-empty string. |
| `file_name` | The filename. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`). |

Example request using HTTP Basic authentication:
Expand Down
1 change: 0 additions & 1 deletion integrations/api_packages_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestPackageGeneric(t *testing.T) {

pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0])
assert.NoError(t, err)
assert.NotNil(t, pd.SemVer)
assert.Nil(t, pd.Metadata)
assert.Equal(t, packageName, pd.Package.Name)
assert.Equal(t, packageVersion, pd.Version.Version)
Expand Down
13 changes: 6 additions & 7 deletions routers/api/packages/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"errors"
"net/http"
"regexp"
"strings"

packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
packages_module "code.gitea.io/gitea/modules/packages"
"code.gitea.io/gitea/routers/api/packages/helper"
packages_service "code.gitea.io/gitea/services/packages"

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

var (
Expand Down Expand Up @@ -97,7 +96,6 @@ func UploadPackage(ctx *context.Context) {
Name: packageName,
Version: packageVersion,
},
SemverCompatible: true,
Creator: ctx.Doer,
},
&packages_service.PackageFileCreationInfo{
Expand Down Expand Up @@ -152,15 +150,16 @@ func DeletePackage(ctx *context.Context) {
func sanitizeParameters(ctx *context.Context) (string, string, string, error) {
packageName := ctx.Params("packagename")
filename := ctx.Params("filename")
packageVersion := ctx.Params("packageversion")

if !packageNameRegex.MatchString(packageName) || !filenameRegex.MatchString(filename) {
return "", "", "", errors.New("Invalid package name or filename")
}

v, err := version.NewSemver(ctx.Params("packageversion"))
if err != nil {
return "", "", "", err
v := strings.TrimSpace(packageVersion)
if v == "" {
return "", "", "", errors.New("Invalid package version")
}

return packageName, v.String(), filename, nil
return packageName, v, filename, nil
}