diff --git a/src/NuGetGallery.Core/CoreStrings.Designer.cs b/src/NuGetGallery.Core/CoreStrings.Designer.cs index 3b5f610a4b..001cf3caa2 100644 --- a/src/NuGetGallery.Core/CoreStrings.Designer.cs +++ b/src/NuGetGallery.Core/CoreStrings.Designer.cs @@ -123,6 +123,15 @@ public static string Manifest_InvalidDependency { } } + /// + /// Looks up a localized string similar to The package manifest contains an invalid Dependency Version: '{0}'. + /// + public static string Manifest_InvalidDependencyVersion { + get { + return ResourceManager.GetString("Manifest_InvalidDependencyVersion", resourceCulture); + } + } + /// /// Looks up a localized string similar to The package manifest contains an invalid ID: '{0}'. /// @@ -168,15 +177,6 @@ public static string Manifest_InvalidVersion { } } - /// - /// Looks up a localized string similar to The version '{0}' is not supported. The NuGet Gallery currently does not currently support Semantic Version 2.0 as it would break older NuGet clients.. - /// - public static string Manifest_InvalidVersionSemVer200 { - get { - return ResourceManager.GetString("Manifest_InvalidVersionSemVer200", resourceCulture); - } - } - /// /// Looks up a localized string similar to The package manifest is missing the Id field. /// diff --git a/src/NuGetGallery.Core/CoreStrings.resx b/src/NuGetGallery.Core/CoreStrings.resx index 0fc99a2625..e865c11acd 100644 --- a/src/NuGetGallery.Core/CoreStrings.resx +++ b/src/NuGetGallery.Core/CoreStrings.resx @@ -168,9 +168,6 @@ The target framework {0} is not supported. - - The version '{0}' is not supported. The NuGet Gallery currently does not currently support Semantic Version 2.0 as it would break older NuGet clients. - (404) Error - Not Found @@ -180,4 +177,7 @@ Negative indexes are invalid. + + The package manifest contains an invalid Dependency Version: '{0}' + \ No newline at end of file diff --git a/src/NuGetGallery.Core/NuGetVersionExtensions.cs b/src/NuGetGallery.Core/NuGetVersionExtensions.cs index 5b83a506a8..28e6f6047b 100644 --- a/src/NuGetGallery.Core/NuGetVersionExtensions.cs +++ b/src/NuGetGallery.Core/NuGetVersionExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Text.RegularExpressions; using NuGet.Versioning; namespace NuGetGallery @@ -23,19 +22,9 @@ public static string Normalize(string version) public static class NuGetVersionExtensions { - private const RegexOptions Flags = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture; - private static readonly Regex SemanticVersionRegex = new Regex(@"^(?\d+(\s*\.\s*\d+){0,3})(?-[a-z][0-9a-z-]*)?$", Flags); - public static string ToNormalizedStringSafe(this NuGetVersion self) { return self != null ? self.ToNormalizedString() : String.Empty; } - - public static bool IsValidVersionForLegacyClients(this NuGetVersion self) - { - var match = SemanticVersionRegex.Match(self.ToString().Trim()); - - return match.Success; - } } } \ No newline at end of file diff --git a/src/NuGetGallery.Core/Packaging/ManifestValidator.cs b/src/NuGetGallery.Core/Packaging/ManifestValidator.cs index c17b1d2613..e7f2481c70 100644 --- a/src/NuGetGallery.Core/Packaging/ManifestValidator.cs +++ b/src/NuGetGallery.Core/Packaging/ManifestValidator.cs @@ -28,7 +28,7 @@ public static IEnumerable Validate(Stream nuspecStream, out Nu catch (Exception ex) { nuspecReader = null; - return new [] { new ValidationResult(ex.Message) }; + return new[] { new ValidationResult(ex.Message) }; } return Enumerable.Empty(); @@ -59,7 +59,7 @@ private static IEnumerable ValidateCore(PackageMetadata packag // Check and validate URL properties foreach (var result in CheckUrls( packageMetadata.GetValueFromMetadata("IconUrl"), - packageMetadata.GetValueFromMetadata("ProjectUrl"), + packageMetadata.GetValueFromMetadata("ProjectUrl"), packageMetadata.GetValueFromMetadata("LicenseUrl"))) { yield return result; @@ -76,12 +76,6 @@ private static IEnumerable ValidateCore(PackageMetadata packag version)); } - var versionValidationResult = ValidateVersion(packageMetadata.Version); - if (versionValidationResult != null) - { - yield return versionValidationResult; - } - // Check framework reference groups var frameworkReferenceGroups = packageMetadata.GetFrameworkReferenceGroups(); if (frameworkReferenceGroups != null) @@ -143,17 +137,19 @@ private static IEnumerable ValidateCore(PackageMetadata packag // Versions if (dependency.VersionRange.MinVersion != null) { - var versionRangeValidationResult = ValidateVersion(dependency.VersionRange.MinVersion); + var versionRangeValidationResult = + ValidateDependencyVersion(dependency.VersionRange.MinVersion); if (versionRangeValidationResult != null) { yield return versionRangeValidationResult; } } - if (dependency.VersionRange.MaxVersion != null + if (dependency.VersionRange.MaxVersion != null && dependency.VersionRange.MaxVersion != dependency.VersionRange.MinVersion) { - var versionRangeValidationResult = ValidateVersion(dependency.VersionRange.MaxVersion); + var versionRangeValidationResult = + ValidateDependencyVersion(dependency.VersionRange.MaxVersion); if (versionRangeValidationResult != null) { yield return versionRangeValidationResult; @@ -164,22 +160,15 @@ private static IEnumerable ValidateCore(PackageMetadata packag } } - private static ValidationResult ValidateVersion(NuGetVersion version) + private static ValidationResult ValidateDependencyVersion(NuGetVersion version) { - if (version.IsSemVer2) + if (version.HasMetadata) { return new ValidationResult(string.Format( CultureInfo.CurrentCulture, - CoreStrings.Manifest_InvalidVersionSemVer200, + CoreStrings.Manifest_InvalidDependencyVersion, version.ToFullString())); } - else if (!version.IsValidVersionForLegacyClients()) - { - return new ValidationResult(string.Format( - CultureInfo.CurrentCulture, - CoreStrings.Manifest_InvalidVersion, - version)); - } return null; } diff --git a/src/NuGetGallery/Services/PackageService.cs b/src/NuGetGallery/Services/PackageService.cs index be3ade7c85..3237196709 100644 --- a/src/NuGetGallery/Services/PackageService.cs +++ b/src/NuGetGallery/Services/PackageService.cs @@ -626,21 +626,6 @@ private static void ValidateNuGetPackageMetadata(PackageMetadata packageMetadata { throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Id", CoreConstants.MaxPackageIdLength); } - if (packageMetadata.Version.IsPrerelease) - { - var release = packageMetadata.Version.Release; - - if (release.Contains(".")) - { - throw new EntityException(Strings.NuGetPackageReleaseVersionWithDot, "Version"); - } - - long temp; - if (long.TryParse(release, out temp)) - { - throw new EntityException(Strings.NuGetPackageReleaseVersionContainsOnlyNumerics, "Version"); - } - } if (packageMetadata.Authors != null && packageMetadata.Authors.Flatten().Length > 4000) { throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Authors", "4000"); diff --git a/src/NuGetGallery/Strings.Designer.cs b/src/NuGetGallery/Strings.Designer.cs index bdf99aeaf3..9c2f92f2d9 100644 --- a/src/NuGetGallery/Strings.Designer.cs +++ b/src/NuGetGallery/Strings.Designer.cs @@ -599,24 +599,6 @@ public static string NuGetPackagePropertyTooLong { } } - /// - /// Looks up a localized string similar to Package {0} invalid: the release label can not only contain numerics.. - /// - public static string NuGetPackageReleaseVersionContainsOnlyNumerics { - get { - return ResourceManager.GetString("NuGetPackageReleaseVersionContainsOnlyNumerics", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Package {0} invalid: no '.' allowed in the release label.. - /// - public static string NuGetPackageReleaseVersionWithDot { - get { - return ResourceManager.GetString("NuGetPackageReleaseVersionWithDot", resourceCulture); - } - } - /// /// Looks up a localized string similar to Package created from API.. /// diff --git a/src/NuGetGallery/Strings.resx b/src/NuGetGallery/Strings.resx index 345ce03c82..934f81ed04 100644 --- a/src/NuGetGallery/Strings.resx +++ b/src/NuGetGallery/Strings.resx @@ -314,12 +314,6 @@ The {1} Team The NuGet package contains an invalid .nuspec file. The error encountered was: '{0}'. Correct the error and try again. - - Package {0} invalid: no '.' allowed in the release label. - - - Package {0} invalid: the release label can not only contain numerics. - SKIPPED! Package file blob {0} already exists diff --git a/tests/NuGetGallery.Core.Facts/Packaging/ManifestValidatorFacts.cs b/tests/NuGetGallery.Core.Facts/Packaging/ManifestValidatorFacts.cs index b14860bcc3..0665cc8f3e 100644 --- a/tests/NuGetGallery.Core.Facts/Packaging/ManifestValidatorFacts.cs +++ b/tests/NuGetGallery.Core.Facts/Packaging/ManifestValidatorFacts.cs @@ -424,44 +424,29 @@ public void ReturnsErrorIfVersionInvalid2() } [Fact] - public void ReturnsErrorIfVersionIsSemVer200() + public void ReturnsNoErrorIfVersionIsSemVer200() { var nuspecStream = CreateNuspecStream(NuSpecSemVer200); - Assert.Equal(new[] { String.Format(CoreStrings.Manifest_InvalidVersionSemVer200, "2.0.0+123") }, GetErrors(nuspecStream)); + Assert.Empty(GetErrors(nuspecStream)); } - [Theory] - [InlineData("1.0.0-beta.1")] - [InlineData("3.0.0-beta+12")] - public void ReturnsErrorIfDependencyVersionIsSemVer200(string version) + [Fact] + public void ReturnsNoErrorIfDependencyVersionIsSemVer200WithoutMetadataPart() { + const string version = "1.0.0-beta.1"; var nuspecStream = CreateNuspecStream(string.Format(NuSpecDependencyVersionPlaceholder, version)); - - Assert.Equal(new[] { String.Format(CoreStrings.Manifest_InvalidVersionSemVer200, version) }, GetErrors(nuspecStream)); - } - - [Theory] - [InlineData("1.0.0-10")] - [InlineData("1.0.0--")] - public void ReturnsErrorIfVersionIsInvalid(string version) - { - // https://github.com/NuGet/NuGetGallery/issues/3226 - - var nuspecStream = CreateNuspecStream(string.Format(NuSpecPlaceholderVersion, version)); - - Assert.Equal(new[] { String.Format(CoreStrings.Manifest_InvalidVersion, version) }, GetErrors(nuspecStream)); + + Assert.Empty(GetErrors(nuspecStream)); } - - [Theory] - [InlineData("1.0.0-10")] - [InlineData("1.0.0--")] - public void ReturnsErrorIfDependencyVersionIsInvalid(string version) + [Fact] + public void ReturnsErrorIfDependencyVersionIsSemVer200WithMetadataPart() { + const string version = "3.0.0-beta+12"; var nuspecStream = CreateNuspecStream(string.Format(NuSpecDependencyVersionPlaceholder, version)); - - Assert.Equal(new[] { String.Format(CoreStrings.Manifest_InvalidVersion, version) }, GetErrors(nuspecStream)); + + Assert.Equal(new[] { String.Format(CoreStrings.Manifest_InvalidDependencyVersion, version) }, GetErrors(nuspecStream)); } [Fact] diff --git a/tests/NuGetGallery.Facts/Services/PackageServiceFacts.cs b/tests/NuGetGallery.Facts/Services/PackageServiceFacts.cs index 80a30368e2..3171ba6826 100644 --- a/tests/NuGetGallery.Facts/Services/PackageServiceFacts.cs +++ b/tests/NuGetGallery.Facts/Services/PackageServiceFacts.cs @@ -702,25 +702,21 @@ private async Task WillThrowIfTheNuGetPackageIdIsLongerThanMaxPackageIdLength() } [Fact] - private async Task WillThrowIfTheNuGetPackageSpecialVersionContainsADot() + private async Task DoesNotThrowIfTheNuGetPackageSpecialVersionContainsADot() { var service = CreateService(); var nugetPackage = CreateNuGetPackage(id: "theId", version: "1.2.3-alpha.0"); - var ex = await Assert.ThrowsAsync(async () => await service.CreatePackageAsync(nugetPackage.Object, new PackageStreamMetadata(), null)); - - Assert.Equal(String.Format(Strings.NuGetPackageReleaseVersionWithDot, "Version"), ex.Message); + await service.CreatePackageAsync(nugetPackage.Object, new PackageStreamMetadata(), null); } [Fact] - private async Task WillThrowIfTheNuGetPackageSpecialVersionContainsOnlyNumbers() + private async Task DoesNotThrowIfTheNuGetPackageSpecialVersionContainsOnlyNumbers() { var service = CreateService(); var nugetPackage = CreateNuGetPackage(id: "theId", version: "1.2.3-12345"); - var ex = await Assert.ThrowsAsync(async () => await service.CreatePackageAsync(nugetPackage.Object, new PackageStreamMetadata(), null)); - - Assert.Equal(String.Format(Strings.NuGetPackageReleaseVersionContainsOnlyNumerics, "Version"), ex.Message); + await service.CreatePackageAsync(nugetPackage.Object, new PackageStreamMetadata(), null); } [Fact]