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

Merge branch "dev" into main #9210

Merged
merged 11 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# on specific relative paths.
**/Scripts/gallery/jquery-3.4.1.js
**/Scripts/gallery/knockout-3.5.1.js
**/Scripts/gallery/moment-2.29.2.js
**/Scripts/gallery/moment-2.29.4.js
2 changes: 1 addition & 1 deletion src/NuGetGallery/App_Start/AppActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void BundlingPostStart()
.Include("~/Scripts/gallery/jquery.validate.unobtrusive-3.2.6.js")
.Include("~/Scripts/gallery/knockout-3.5.1.js")
.Include("~/Scripts/gallery/bootstrap.js")
.Include("~/Scripts/gallery/moment-2.29.2.js")
.Include("~/Scripts/gallery/moment-2.29.4.js")
.Include("~/Scripts/gallery/common.js")
.Include("~/Scripts/gallery/autocomplete.js");
BundleTable.Bundles.Add(scriptBundle);
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@
<Content Include="App_Data\Files\Content\Symbols-Configuration.json" />
<Content Include="Scripts\gallery\instrumentation.js" />
<Content Include="Scripts\gallery\knockout-3.5.1.js" />
<Content Include="Scripts\gallery\moment-2.29.4.js" />
<Content Include="Scripts\gallery\page-list-packages.js" />
<Content Include="Scripts\gallery\syntaxhighlight.js" />
<Content Include="Views\Shared\SiteMenu.cshtml">
Expand Down Expand Up @@ -1863,7 +1864,6 @@
<Content Include="Scripts\gallery\jquery.validate.unobtrusive-3.2.6.js" />
<Content Include="Scripts\gallery\knockout-projections.js" />
<Content Include="Scripts\gallery\md5.js" />
<Content Include="Scripts\gallery\moment-2.29.2.js" />
<Content Include="Scripts\gallery\page-about.js" />
<Content Include="Scripts\gallery\page-account.js" />
<Content Include="Scripts\gallery\page-add-organization.js" />
Expand Down Expand Up @@ -2271,7 +2271,7 @@
<Version>2.8.3</Version>
</PackageReference>
<PackageReference Include="Moment.js">
<Version>2.29.2</Version>
<Version>2.29.4</Version>
</PackageReference>
<PackageReference Include="MvcTreeView">
<Version>1.4.0</Version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! moment.js
//! version : 2.29.2
//! version : 2.29.4
//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
//! license : MIT
//! momentjs.com
Expand Down Expand Up @@ -2454,7 +2454,7 @@
function preprocessRFC2822(s) {
// Remove comments and folding whitespace and replace multiple-spaces with a single space
return s
.replace(/\([^)]*\)|[\n\t]/g, ' ')
.replace(/\([^()]*\)|[\n\t]/g, ' ')
.replace(/(\s\s+)/g, ' ')
.replace(/^\s\s*/, '')
.replace(/\s\s*$/, '');
Expand Down Expand Up @@ -5635,7 +5635,7 @@

//! moment.js

hooks.version = '2.29.2';
hooks.version = '2.29.4';

setHookCallback(createLocal);

Expand Down
6 changes: 5 additions & 1 deletion src/NuGetGallery/Services/MarkdownService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ private RenderedMarkdownResult GetHtmlFromMarkdownMarkdig(string markdownString,
.UseEmojiAndSmiley()
.UseAutoLinks()
.UseReferralLinks("noopener noreferrer nofollow")
.UseAutoIdentifiers()
.UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)
.DisableHtml() //block inline html
.UseBootstrap()
Expand Down Expand Up @@ -267,7 +268,10 @@ private RenderedMarkdownResult GetHtmlFromMarkdownMarkdig(string markdownString,
// Allow only http or https links in markdown. Transform link to https for known domains.
if (!PackageHelper.TryPrepareUrlForRendering(linkInline.Url, out string readyUriString))
{
linkInline.Url = string.Empty;
if (!linkInline.Url.StartsWith("#")) //allow internal section links
{
linkInline.Url = string.Empty;
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@<text>Delete</text>)

@ViewHelpers.AlertWarning(@<text><strong class="keywords">Important</strong>
Once your organization is deleted you cannot undo it. <a href="https://go.microsoft.com/fwlink/?linkid=862770">Read more.</a>
Once your organization is deleted you cannot undo it. <b>The organization name will be reserved and it will not be able to be reused.</b> <a href="https://go.microsoft.com/fwlink/?linkid=862770">Read more.</a>
</text>)
<p>
When your organization is deleted we will:<br />
Expand Down
23 changes: 13 additions & 10 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
{
Id = "package-manager",
CommandPrefix = "PM> ",
InstallPackageCommands = new [] { string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version) },
InstallPackageCommands = new [] { string.Format("NuGet\\Install-Package {0} -Version {1}", Model.Id, Model.Version) },
AlertLevel = AlertLevel.Info,
AlertMessage = "This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of <a href='https://docs.microsoft.com/en-us/nuget/reference/ps-reference/ps-ref-install-package'>Install-Package</a>."

},

new PackageManagerViewModel(".NET CLI")
Expand Down Expand Up @@ -208,7 +211,7 @@
@ViewHelpers.AlertWarning(
@<text>
@Html.Raw(packageManager.AlertMessage)
</text>);
</text>, true);
break;
default:
break;
Expand Down Expand Up @@ -1342,14 +1345,14 @@

@if (Model.IsMarkdigMdSyntaxHighlightEnabled)
{
@ViewHelpers.IncludeSyntaxHighlightScript();

<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
});
@ViewHelpers.IncludeSyntaxHighlightScript();
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
});
</script>
}

Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/Views/Users/DeleteAccount.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
else
{
@ViewHelpers.AlertWarning(@<text><strong class="keywords">Important</strong>
Once your account is deleted you cannot undo it. <a href="https://go.microsoft.com/fwlink/?linkid=862770">Read more.</a>
Once your account is deleted you cannot undo it. <b>The account name will be reserved and it will not be able to be reused.</b> <a href="https://go.microsoft.com/fwlink/?linkid=862770">Read more.</a>
</text>)
<p>
When you account is deleted we will:<br />
<ul>
<li>Revoke your api key(s).</li>
<li>Revoke your API key(s).</li>
<li>Remove you as the owner for any packages you own.</li>
<li>Remove your ownership from any ID prefix reservations and delete any ID prefix reservations that you were the only owner of.</li>
<li>Remove you from any organizations that you are a member of.</li>
Expand Down
43 changes: 29 additions & 14 deletions tests/NuGetGallery.Facts/Services/MarkdownServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public void EncodesHtmlInMarkdown(string originalMd, string expectedHtml, bool i
}

[Theory]
[InlineData("# Heading", "<h1>Heading</h1>", true, 0)]
[InlineData("# Heading", "<h1 id=\"heading\">Heading</h1>", true, 0)]
[InlineData("# Heading", "<h1>Heading</h1>", false, 0)]
[InlineData("# Heading", "<h2>Heading</h2>", true, 1)]
[InlineData("# Heading", "<h2 id=\"heading\">Heading</h2>", true, 1)]
[InlineData("# Heading", "<h2>Heading</h2>", false, 1)]
[InlineData("# Heading", "<h6>Heading</h6>", true, 6)]
[InlineData("# Heading", "<h6 id=\"heading\">Heading</h6>", true, 6)]
[InlineData("# Heading", "<h6>Heading</h6>", false, 6)]
[InlineData("# Heading", "<h6>Heading</h6>", true, 7)]
[InlineData("# Heading", "<h6 id=\"heading\">Heading</h6>", true, 7)]
[InlineData("# Heading", "<h6>Heading</h6>", false, 7)]
[InlineData("# Heading", "<h6>Heading</h6>", true, 5)]
[InlineData("# Heading", "<h6 id=\"heading\">Heading</h6>", true, 5)]
[InlineData("# Heading", "<h6>Heading</h6>", false, 5)]
public void EncodesHtmlInMarkdownWithAdaptiveHeader(string originalMd, string expectedHtml, bool isMarkdigMdRenderingEnabled, int incrementHeadersBy)
{
Expand All @@ -71,11 +71,11 @@ public void EncodesHtmlInMarkdownWithAdaptiveHeader(string originalMd, string ex
}

[Theory]
[InlineData("# Heading", "<h2>Heading</h2>", false, true)]
[InlineData("# Heading", "<h2 id=\"heading\">Heading</h2>", false, true)]
[InlineData("# Heading", "<h2>Heading</h2>", false, false)]
[InlineData("<!-- foo --> <!-- foo \n bar --> baz", "<p>baz</p>", false, true)]
[InlineData("<!-- foo --> <!-- foo \n bar --> baz", "<p>baz</p>", false, false)]
[InlineData("\ufeff# Heading with BOM", "<h2>Heading with BOM</h2>", false, true)]
[InlineData("\ufeff# Heading with BOM", "<h2 id=\"heading-with-bom\">Heading with BOM</h2>", false, true)]
[InlineData("\ufeff# Heading with BOM", "<h2>Heading with BOM</h2>", false, false)]
[InlineData("- List", "<ul>\n<li>List</li>\n</ul>", false, true)]
[InlineData("- List", "<ul>\r\n<li>List</li>\r\n</ul>", false, false)]
Expand Down Expand Up @@ -103,8 +103,8 @@ public void EncodesHtmlInMarkdownWithAdaptiveHeader(string originalMd, string ex
[InlineData("![image](https://www.asp.net/fake.jpg)", "<p><img src=\"https://www.asp.net/fake.jpg\" alt=\"image\" /></p>", false, false)]
[InlineData("![image](http://www.otherurl.net/fake.jpg)", "<p><img src=\"https://www.otherurl.net/fake.jpg\" class=\"img-fluid\" alt=\"image\" /></p>", true, true)]
[InlineData("![image](http://www.otherurl.net/fake.jpg)", "<p><img src=\"https://www.otherurl.net/fake.jpg\" alt=\"image\" /></p>", true, false)]
[InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "<h3>License</h3>\n<pre><code>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n</code></pre>", false, true)]
[InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "<h3>License</h3>\n<pre><code>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n</code></pre>", false, true)]
[InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "<h3 id=\"license\">License</h3>\n<pre><code>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n</code></pre>", false, true)]
[InlineData("## License\n\tLicensed under the Apache License, Version 2.0 (the \"License\");", "<h3 id=\"license\">License</h3>\n<pre><code>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n</code></pre>", false, true)]
public void ConvertsMarkdownToHtml(string originalMd, string expectedHtml, bool imageRewriteExpected, bool isMarkdigMdRenderingEnabled)
{
_featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(isMarkdigMdRenderingEnabled);
Expand Down Expand Up @@ -223,12 +223,11 @@ Some text
Assert.False(readMeResult.ImagesRewritten);
}

[Fact]
public void TestToHtmlWithAutoLinks()
[Theory]
[InlineData("This is a http://www.google.com URL and https://www.google.com", "<p>This is a <a href=\"http://www.google.com/\" rel=\"noopener noreferrer nofollow\">http://www.google.com</a> URL and <a href=\"https://www.google.com/\" rel=\"noopener noreferrer nofollow\">https://www.google.com</a></p>")]
[InlineData("# This is a heading\n[Link](#this-is-a-heading)", "<h2 id=\"this-is-a-heading\">This is a heading</h2>\n<p><a href=\"#this-is-a-heading\" rel=\"noopener noreferrer nofollow\">Link</a></p>")]
public void TestToHtmlWithAutoLinks(string originalMd, string expectedHtml)
{
var originalMd = "This is a http://www.google.com URL and https://www.google.com";

var expectedHtml = "<p>This is a <a href=\"http://www.google.com/\" rel=\"noopener noreferrer nofollow\">http://www.google.com</a> URL and <a href=\"https://www.google.com/\" rel=\"noopener noreferrer nofollow\">https://www.google.com</a></p>";
_featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(true);
var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd);
Assert.Equal(expectedHtml, readMeResult.Content);
Expand All @@ -244,6 +243,22 @@ public void TestToHtmlWithStrikethrough(string originalMd, string expectedHtml)
Assert.Equal(expectedHtml, readMeResult.Content);
Assert.False(readMeResult.ImagesRewritten);
}

[Theory]
[InlineData("# Heading", "<h2 id=\"heading\">Heading</h2>")]
[InlineData("# This is a heading", "<h2 id=\"this-is-a-heading\">This is a heading</h2>")]
[InlineData("# This - is a &@! heading _ with . and ! -", "<h2 id=\"this-is-a-heading_with.and\">This - is a &amp;@! heading _ with . and ! -</h2>")]
[InlineData("# This is a *heading*", "<h2 id=\"this-is-a-heading\">This is a <em>heading</em></h2>")]
[InlineData("# This is a [heading](https://www.google.com)", "<h2 id=\"this-is-a-heading\">This is a <a href=\"https://www.google.com/\" rel=\"noopener noreferrer nofollow\">heading</a></h2>")]
[InlineData("# Heading\n# Heading", "<h2 id=\"heading\">Heading</h2>\n<h2 id=\"heading-1\">Heading</h2>")]
[InlineData("# 1.0 This is a heading", "<h2 id=\"this-is-a-heading\">1.0 This is a heading</h2>")]
[InlineData("# 1.0 & ^ % *\n# 1.0 & ^ % *", "<h2 id=\"section\">1.0 &amp; ^ % *</h2>\n<h2 id=\"section-1\">1.0 &amp; ^ % *</h2>")]
public void TestToHtmlWithAutoIdentifiers(string originalMd, string expectedHtml)
{
_featureFlagService.Setup(x => x.IsMarkdigMdRenderingEnabled()).Returns(true);
var readMeResult = _markdownService.GetHtmlFromMarkdown(originalMd);
Assert.Equal(expectedHtml, readMeResult.Content);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public StaticAssetsTests(ITestOutputHelper testOutputHelper) : base(testOutputHe
"Scripts/gallery/jquery.validate.unobtrusive-3.2.6.js",
"Scripts/gallery/knockout-3.4.2.js",
"Scripts/gallery/bootstrap.js",
"Scripts/gallery/moment-2.29.2.js",
"Scripts/gallery/moment-2.29.4.js",
"Scripts/gallery/common.js",
"Scripts/gallery/autocomplete.js",
}
Expand Down