diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-12-21 04:20:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 22:20:23 -0500 |
commit | 86ace4b5c2cd6e02eae6814a81992c2591b6448d (patch) | |
tree | e68f970477c46a833f69f65a65ed180e726d18f5 /routers | |
parent | fe6608f72bc2c71e30665126b7257650987d8c73 (diff) | |
download | gitea-86ace4b5c2cd6e02eae6814a81992c2591b6448d.tar.gz gitea-86ace4b5c2cd6e02eae6814a81992c2591b6448d.zip |
Normalize NuGet package version on upload (#22186)
Fixes #22178
After this change upload versions with different semver metadata are
treated as the same version and trigger a duplicated version error.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/packages/nuget/api_v2.go | 2 | ||||
-rw-r--r-- | routers/api/packages/nuget/api_v3.go | 22 |
2 files changed, 4 insertions, 20 deletions
diff --git a/routers/api/packages/nuget/api_v2.go b/routers/api/packages/nuget/api_v2.go index c545d0fc4e..7d0ac64a8a 100644 --- a/routers/api/packages/nuget/api_v2.go +++ b/routers/api/packages/nuget/api_v2.go @@ -344,7 +344,7 @@ func createEntry(l *linkBuilder, pd *packages_model.PackageDescriptor, withNames Content: content, Properties: &FeedEntryProperties{ Version: pd.Version.Version, - NormalizedVersion: normalizeVersion(pd.SemVer), + NormalizedVersion: pd.Version.Version, Authors: metadata.Authors, Dependencies: buildDependencyString(metadata), Description: metadata.Description, diff --git a/routers/api/packages/nuget/api_v3.go b/routers/api/packages/nuget/api_v3.go index b5900b6c0b..28626f9294 100644 --- a/routers/api/packages/nuget/api_v3.go +++ b/routers/api/packages/nuget/api_v3.go @@ -4,15 +4,11 @@ package nuget import ( - "bytes" - "fmt" "sort" "time" packages_model "code.gitea.io/gitea/models/packages" nuget_module "code.gitea.io/gitea/modules/packages/nuget" - - "github.com/hashicorp/go-version" ) // https://docs.microsoft.com/en-us/nuget/api/service-index#resources @@ -95,8 +91,8 @@ func createRegistrationIndexResponse(l *linkBuilder, pds []*packages_model.Packa { RegistrationPageURL: l.GetRegistrationIndexURL(pds[0].Package.Name), Count: len(pds), - Lower: normalizeVersion(pds[0].SemVer), - Upper: normalizeVersion(pds[len(pds)-1].SemVer), + Lower: pds[0].Version.Version, + Upper: pds[len(pds)-1].Version.Version, Items: items, }, }, @@ -173,7 +169,7 @@ type PackageVersionsResponse struct { func createPackageVersionsResponse(pds []*packages_model.PackageDescriptor) *PackageVersionsResponse { versions := make([]string, 0, len(pds)) for _, pd := range pds { - versions = append(versions, normalizeVersion(pd.SemVer)) + versions = append(versions, pd.Version.Version) } return &PackageVersionsResponse{ @@ -248,15 +244,3 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor) RegistrationIndexURL: l.GetRegistrationIndexURL(latest.Package.Name), } } - -// normalizeVersion removes the metadata -func normalizeVersion(v *version.Version) string { - var buf bytes.Buffer - segments := v.Segments64() - fmt.Fprintf(&buf, "%d.%d.%d", segments[0], segments[1], segments[2]) - pre := v.Prerelease() - if pre != "" { - fmt.Fprintf(&buf, "-%s", pre) - } - return buf.String() -} |