From b72d197315957ce47642d7de86026797f6958ef9 Mon Sep 17 00:00:00 2001 From: lyndaidaii <64443925+lyndaidaii@users.noreply.github.com> Date: Thu, 1 Apr 2021 12:28:21 -0700 Subject: [PATCH] reject empty readme file & fix error message for invalid extension (#8473) --- .../Services/PackageMetadataValidationService.cs | 10 ++++++++++ src/NuGetGallery/Strings.Designer.cs | 11 ++++++++++- src/NuGetGallery/Strings.resx | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/NuGetGallery/Services/PackageMetadataValidationService.cs b/src/NuGetGallery/Services/PackageMetadataValidationService.cs index 959f621c5d..f384bfc37b 100644 --- a/src/NuGetGallery/Services/PackageMetadataValidationService.cs +++ b/src/NuGetGallery/Services/PackageMetadataValidationService.cs @@ -458,6 +458,16 @@ private async Task CheckReadmeMetadataAsync(PackageArch } var readmeFileEntry = nuGetPackage.GetEntry(readmeFilePath); + + if (readmeFileEntry.Length == 0) + { + return PackageValidationResult.Invalid( + string.Format( + Strings.ReadmeErrorEmpty, + Strings.UploadPackage_ReadmeFileType, + readmeFilePath)); + } + if (readmeFileEntry.Length > MaxAllowedReadmeLengthForUploading) { return PackageValidationResult.Invalid( diff --git a/src/NuGetGallery/Strings.Designer.cs b/src/NuGetGallery/Strings.Designer.cs index 51d32b707e..c23dc2cb63 100644 --- a/src/NuGetGallery/Strings.Designer.cs +++ b/src/NuGetGallery/Strings.Designer.cs @@ -1588,6 +1588,15 @@ public class Strings { } } + /// + /// Looks up a localized string similar to The readme file '{0}' cannot be empty.. + /// + public static string ReadmeErrorEmpty { + get { + return ResourceManager.GetString("ReadmeErrorEmpty", resourceCulture); + } + } + /// /// Looks up a localized string similar to '{0}' is not a valid Markdown Documentation source type.. /// @@ -2598,7 +2607,7 @@ public class Strings { } /// - /// Looks up a localized string similar to The readme file has an invalid extension '{0}'. Extension must be one of the following: {1}.. + /// Looks up a localized string similar to The readme file has an invalid extension '{0}'. The extension must be: '{1}'.. /// public static string UploadPackage_InvalidReadmeFileExtension { get { diff --git a/src/NuGetGallery/Strings.resx b/src/NuGetGallery/Strings.resx index b841942641..a7b8dcbfc9 100644 --- a/src/NuGetGallery/Strings.resx +++ b/src/NuGetGallery/Strings.resx @@ -1166,7 +1166,7 @@ The {1} Team The <readme> element is not currently supported. - The readme file has an invalid extension '{0}'. Extension must be one of the following: {1}. + The readme file has an invalid extension '{0}'. The extension must be: '{1}'. {0} is the readme file extension specified in the .nuspec, {1} is the list of allowed extensions @@ -1215,4 +1215,7 @@ The {1} Team The package ID is reserved. You can upload your package with a different package ID. Reach out to <a href="mailto:support@nuget.org">support@nuget.org</a> if you have questions. + + The readme file '{0}' cannot be empty. + \ No newline at end of file