Skip to content
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

reject empty readme file & fix error message for invalid extension #8464

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/NuGetGallery/Services/PackageMetadataValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ private async Task<PackageValidationResult> CheckReadmeMetadataAsync(PackageArch
}

var readmeFileEntry = nuGetPackage.GetEntry(readmeFilePath);

if (readmeFileEntry.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a readme with just whitespace? Would it be worth rejecting those too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, probably not rejecting those? @chgill-MSFT what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep a consistent behavior on validations between the server and client.
If the client accepts a whitespace readme but the server rejects it, it's not a good customer experience.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our validations are already a superset of client, by design. I don't think an empty string README is useful. But also, it's the author's fault if they do this. My guess it is likely unintentional and not a helpful content to the user. But I don't feel strongly.

{
return PackageValidationResult.Invalid(
string.Format(
Strings.ReadmeErrorEmpty,
Strings.UploadPackage_ReadmeFileType,
readmeFilePath));
}

if (readmeFileEntry.Length > MaxAllowedReadmeLengthForUploading)
{
return PackageValidationResult.Invalid(
Expand Down
11 changes: 10 additions & 1 deletion src/NuGetGallery/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/NuGetGallery/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ The {1} Team</value>
<value>The &lt;readme&gt; element is not currently supported.</value>
</data>
<data name="UploadPackage_InvalidReadmeFileExtension" xml:space="preserve">
<value>The readme file has an invalid extension '{0}'. Extension must be one of the following: {1}.</value>
<value>The readme file has an invalid extension '{0}'. The extension must be: '{1}'.</value>
<comment>{0} is the readme file extension specified in the .nuspec, {1} is the list of allowed extensions</comment>
</data>
<data name="UploadPackage_ReadmeFileType" xml:space="preserve">
Expand Down Expand Up @@ -1215,4 +1215,7 @@ The {1} Team</value>
<data name="UploadPackage_OwnerlessIdNamespaceConflictHtml" xml:space="preserve">
<value>The package ID is reserved. You can upload your package with a different package ID. Reach out to &lt;a href="mailto:support@nuget.org"&gt;support@nuget.org&lt;/a&gt; if you have questions.</value>
</data>
<data name="ReadmeErrorEmpty" xml:space="preserve">
<value>The readme file '{0}' cannot be empty.</value>
</data>
</root>