Skip to content

Commit 436398e

Browse files
authored
Merge pull request #8818 from NuGet/dev
[ReleasePrep][2021.09.21] RI of dev into main
2 parents 73c5d8a + 66e57da commit 436398e

13 files changed

Lines changed: 215 additions & 50 deletions

src/NuGetGallery/App_Data/Files/Content/Trusted-Image-Domains.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"api.travis-ci.com",
99
"api.travis-ci.org",
1010
"app.fossa.io",
11+
"app.fossa.com",
1112
"badge.fury.io",
1213
"badgen.net",
1314
"badges.gitter.im",
1415
"bettercodehub.com",
1516
"buildstats.info",
1617
"cdn.jsdelivr.net",
18+
"cdn.syncfusion.com",
1719
"ci.appveyor.com",
1820
"circleci.com",
1921
"codecov.io",

src/NuGetGallery/Extensions/NumberExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ public static string ToUserFriendlyBytesLabel(this long bytes)
6969
return "0 bytes";
7070
}
7171

72+
/// <summary>
73+
/// Format the number of bytes into a user-friendly display label.
74+
/// </summary>
75+
/// <param name="bytes"></param>
76+
/// <returns></returns>
77+
public static string ToUserFriendlyBytesLabel(this int bytes)
78+
=> ToUserFriendlyBytesLabel((long)bytes);
79+
7280
/// <summary>
7381
/// Format the number to a 1 decimal precision plus a letter to represent the scale (K for kilo, M for mega, or B for billion)
7482
/// </summary>

src/NuGetGallery/GalleryConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static class GalleryConstants
2727
public const int GravatarCacheDurationSeconds = 300;
2828

2929
public const int MaxEmailSubjectLength = 255;
30+
public const int MaxFileLengthBytes = 1024 * 1024; // 1MB for License, Icon, readme file
3031
internal static readonly NuGetVersion MaxSupportedMinClientVersion = new NuGetVersion("5.9.0.0");
3132
public const string PackageFileDownloadUriTemplate = "packages/{0}/{1}/download";
3233

src/NuGetGallery/Scripts/gallery/page-display-package-v2.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,31 @@
5050
// Configure package manager copy buttons
5151
function configureCopyButton(id) {
5252
var copyButton = $('#' + id + '-button');
53-
copyButton.popover({
54-
trigger: 'manual',
55-
// Windows Narrator does not announce popovers' content. See: https://github.com/twbs/bootstrap/issues/18618
56-
// We can force Narrator to announce the content by changing
57-
// the popover's role from 'tooltip' to 'status'.
58-
// Modified from: https://github.com/twbs/bootstrap/blob/f17f882df292b29323f1e1da515bd16f326cee4a/js/popover.js#L28
59-
template: '<div class="popover" role="status"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
60-
});
53+
var copyButtonDom = copyButton.get(0);
54+
copyButton.popover({ trigger: 'manual' });
6155

6256
copyButton.click(function () {
6357
var text = $('#' + id + '-text').text().trim();
6458
window.nuget.copyTextToClipboard(text, copyButton);
6559

6660
copyButton.popover('show');
61+
62+
// Windows Narrator does not announce popovers' content. See: https://github.com/twbs/bootstrap/issues/18618
63+
// We can force Narrator to announce the popover's content by "flashing"
64+
// the copy button's ARIA label.
65+
var originalLabel = copyButtonDom.ariaLabel;
66+
copyButtonDom.ariaLabel = "";
67+
6768
setTimeout(function () {
6869
copyButton.popover('destroy');
69-
}, 1000);
70+
71+
// We need to restore the copy button's original ARIA label.
72+
// Wait 0.15 seconds for the popover to fade away first.
73+
// Otherwise, the screen reader will re-announce the popover's content.
74+
setTimeout(function () {
75+
copyButtonDom.ariaLabel = originalLabel;
76+
}, 200);
77+
}, 1500);
7078

7179
window.nuget.sendMetric("CopyInstallCommand", 1, {
7280
ButtonId: id,

src/NuGetGallery/Scripts/gallery/page-display-package.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,31 @@ $(function () {
9090
// Configure package manager copy buttons
9191
function configureCopyButton(id) {
9292
var copyButton = $('#' + id + '-button');
93-
copyButton.popover({
94-
trigger: 'manual',
95-
// Windows Narrator does not announce popovers' content. See: https://github.com/twbs/bootstrap/issues/18618
96-
// We can force Narrator to announce the content by changing
97-
// the popover's role from 'tooltip' to 'status'.
98-
// Modified from: https://github.com/twbs/bootstrap/blob/f17f882df292b29323f1e1da515bd16f326cee4a/js/popover.js#L28
99-
template: '<div class="popover" role="status"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
100-
});
93+
var copyButtonDom = copyButton.get(0);
94+
copyButton.popover({ trigger: 'manual' });
10195

10296
copyButton.click(function () {
10397
var text = $('#' + id + '-text').text().trim();
10498
window.nuget.copyTextToClipboard(text, copyButton);
10599
copyButton.popover('show');
100+
101+
// Windows Narrator does not announce popovers' content. See: https://github.com/twbs/bootstrap/issues/18618
102+
// We can force Narrator to announce the popover's content by "flashing"
103+
// the copy button's ARIA label.
104+
var originalLabel = copyButtonDom.ariaLabel;
105+
copyButtonDom.ariaLabel = "";
106+
106107
setTimeout(function () {
107108
copyButton.popover('destroy');
108-
}, 1000);
109+
110+
// We need to restore the copy button's original ARIA label.
111+
// Wait 0.15 seconds for the popover to fade away first.
112+
// Otherwise, the screen reader will re-announce the popover's content.
113+
setTimeout(function () {
114+
copyButtonDom.ariaLabel = originalLabel;
115+
}, 200);
116+
}, 1500);
117+
109118
window.nuget.sendMetric("CopyInstallCommand", 1, {
110119
ButtonId: id,
111120
PackageId: packageId,

src/NuGetGallery/Services/PackageMetadataValidationService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public class PackageMetadataValidationService : IPackageMetadataValidationServic
5454
/// in plain text and small enough to not cause issues with scanning through such file a few times
5555
/// during the package validation.
5656
/// </remarks>
57-
private const long MaxAllowedLicenseLengthForUploading = 1024 * 1024; // 1 MB
58-
private const long MaxAllowedIconLengthForUploading = 1024 * 1024; // 1 MB
57+
private const int MaxAllowedLicenseLengthForUploading = GalleryConstants.MaxFileLengthBytes;
58+
private const int MaxAllowedIconLengthForUploading = GalleryConstants.MaxFileLengthBytes;
5959
private const int MaxAllowedLicenseNodeValueLength = 500;
6060
// 1 MB Keep consistent with icon, license for now, change value later once we define the size
61-
private const long MaxAllowedReadmeLengthForUploading = 1024 * 1024;
61+
private const int MaxAllowedReadmeLengthForUploading = GalleryConstants.MaxFileLengthBytes;
6262
private const string LicenseNodeName = "license";
6363
private const string IconNodeName = "icon";
6464
private const string AllowedLicenseVersion = "1.0.0";

src/NuGetGallery/Services/PackageVulnerabilitiesCacheService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public void RefreshCache(IServiceScopeFactory serviceScopeFactory)
8686
ikv.GroupBy(kv => kv.PackageKey, kv => kv.Vulnerability)
8787
// - build the inner dictionaries, all under the same <id>, each keyed by <package key>
8888
.ToDictionary(kv => kv.Key,
89-
kv => kv.ToList().AsReadOnly() as IReadOnlyList<PackageVulnerability>));
89+
kv => kv.ToList().AsReadOnly() as IReadOnlyList<PackageVulnerability>),
90+
// we need this lookup to be case insensitive for package details page load URLs to work regardless of case
91+
StringComparer.InvariantCultureIgnoreCase);
9092
}
9193

9294
stopwatch.Stop();

src/NuGetGallery/Services/ReadMeService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class ReadMeService : IReadMeService
2121
internal const string TypeFile = "File";
2222
internal const string TypeWritten = "Written";
2323

24-
internal const int MaxMdLengthBytes = 8000;
24+
internal const int MaxAllowedReadmeBytes = GalleryConstants.MaxFileLengthBytes;
2525
private const string UrlHostRequirement = "raw.githubusercontent.com";
2626

2727
private static readonly TimeSpan UrlTimeout = TimeSpan.FromSeconds(10);
@@ -235,10 +235,10 @@ internal static async Task<string> GetReadMeMdAsync(ReadMeRequest readMeRequest,
235235

236236
if (TypeWritten.Equals(readMeType, StringComparison.InvariantCultureIgnoreCase))
237237
{
238-
if (encoding.GetByteCount(readMeRequest.SourceText) > MaxMdLengthBytes)
238+
if (encoding.GetByteCount(readMeRequest.SourceText) > MaxAllowedReadmeBytes)
239239
{
240240
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
241-
Strings.ReadMeMaxLengthExceeded, MaxMdLengthBytes));
241+
Strings.ReadMeMaxLengthExceeded, MaxAllowedReadmeBytes));
242242
}
243243
return readMeRequest.SourceText;
244244
}
@@ -272,7 +272,7 @@ private static async Task<string> GetReadMeMdFromPostedFileAsync(HttpPostedFileB
272272

273273
using (var readMeMdStream = readMeMdPostedFile.InputStream)
274274
{
275-
return await ReadMaxAsync(readMeMdStream, MaxMdLengthBytes, encoding);
275+
return await ReadMaxAsync(readMeMdStream, MaxAllowedReadmeBytes, encoding);
276276
}
277277
}
278278

@@ -292,7 +292,7 @@ private static async Task<string> GetReadMeMdFromUrlAsync(string readMeMdUrl, En
292292
{
293293
using (var httpStream = await client.GetStreamAsync(readMeMdUrl))
294294
{
295-
return await ReadMaxAsync(httpStream, MaxMdLengthBytes, encoding);
295+
return await ReadMaxAsync(httpStream, MaxAllowedReadmeBytes, encoding);
296296
}
297297
}
298298
}

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
<div class="copy-button">
196196
<button id="@packageManager.Id-button" class="btn btn-default btn-warning" type="button"
197197
data-toggle="popover" data-placement="bottom" data-content="Copied."
198-
aria-label="@packageManager.CopyLabel" aria-live="polite" role="button">
198+
aria-label="@packageManager.CopyLabel" role="button">
199199
<span class="ms-Icon ms-Icon--Copy" aria-hidden="true"></span>
200200
</button>
201201
</div>

src/NuGetGallery/Views/Packages/DisplayPackageV2.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
<div class="copy-button">
192192
<button id="@packageManager.Id-button" class="btn btn-default btn-warning" type="button"
193193
data-toggle="popover" data-placement="bottom" data-content="Copied."
194-
aria-label="@packageManager.CopyLabel" aria-live="polite" role="button">
194+
aria-label="@packageManager.CopyLabel" role="button">
195195
<span class="ms-Icon ms-Icon--Copy" aria-hidden="true"></span>
196196
</button>
197197
</div>

0 commit comments

Comments
 (0)