Skip to content

Commit a59c580

Browse files
authored
Merge pull request #3 from managedcode/codex/fix-all-comments
Restore ArrayPool import
2 parents 0c8ea83 + 4d46481 commit a59c580

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

ManagedCode.MimeTypes.Sync/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ internal static class MimeTypeSyncTool
1616
"https://raw.githubusercontent.com/apache/httpd/trunk/docs/conf/mime.types"
1717
};
1818

19-
private static readonly char[] MimeTypeSeparators = new[] { ' ', '\t' };
20-
2119
public static async Task<int> RunAsync(string[] args)
2220
{
2321
try
@@ -147,7 +145,7 @@ private static Dictionary<string, string> ParseMimeTypesListing(string source, b
147145
continue;
148146
}
149147

150-
var parts = line.Split(MimeTypeSeparators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
148+
var parts = line.Split(' ', '\t', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
151149
if (parts.Length < 2)
152150
{
153151
continue;

ManagedCode.MimeTypes.Tests/GeneratorTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,18 @@ public void GetExtensionsShouldReturnKnownExtensions()
6161
[Fact]
6262
public void RuntimeRegistrationShouldUpdateLookups()
6363
{
64-
const string extension = "customext";
65-
const string mime = "application/x-custom";
66-
6764
try
6865
{
69-
MimeHelper.RegisterMimeType(extension, mime);
70-
MimeHelper.GetMimeType($"file.{extension}").ShouldBe(mime);
66+
MimeHelper.RegisterMimeType("customext", "application/x-custom");
67+
MimeHelper.GetMimeType("file.customext").ShouldBe("application/x-custom");
7168

72-
MimeHelper.TryGetExtensions(mime, out var extensions).ShouldBeTrue();
73-
extensions.ShouldContain($".{extension}");
69+
MimeHelper.TryGetExtensions("application/x-custom", out var extensions).ShouldBeTrue();
70+
extensions.ShouldContain(".customext");
7471
}
7572
finally
7673
{
77-
MimeHelper.UnregisterMimeType(extension).ShouldBeTrue();
78-
MimeHelper.GetMimeType(extension).ShouldBe("application/octet-stream");
74+
MimeHelper.UnregisterMimeType("customext").ShouldBeTrue();
75+
MimeHelper.GetMimeType("customext").ShouldBe("application/octet-stream");
7976
}
8077
}
81-
}
78+
}

ManagedCode.MimeTypes/MimeHelper.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static partial class MimeHelper
3131

3232
private static readonly Regex ScriptPattern = new(@"^(?:application|text)/(?:javascript|ecmascript|x-php|x-sh|x-shellscript|x-python|x-ruby|x-perl)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
3333

34-
private static readonly SearchValues<char> QueryFragmentSeparators = SearchValues.Create("?#");
34+
private static readonly SearchValues<char> QueryFragmentSeparators = SearchValues.Create(new[] { '?', '#' });
3535

3636
private static readonly HashSet<string> ScriptMimeSet = new(StringComparer.OrdinalIgnoreCase)
3737
{
@@ -605,40 +605,34 @@ private static int ReadUpTo(Stream stream, byte[] buffer, int count)
605605
{
606606
if (header.Length >= 12 && header[..4].SequenceEqual(RiffSignature))
607607
{
608-
if (header.Length >= 12)
608+
var format = header.Slice(8, 4);
609+
if (format.SequenceEqual(WebpFourCC))
609610
{
610-
var format = header.Slice(8, 4);
611-
if (format.SequenceEqual(WebpFourCC))
612-
{
613-
return "image/webp";
614-
}
611+
return "image/webp";
612+
}
615613

616-
if (format.SequenceEqual(AviFourCC))
617-
{
618-
return "video/x-msvideo";
619-
}
614+
if (format.SequenceEqual(AviFourCC))
615+
{
616+
return "video/x-msvideo";
617+
}
620618

621-
if (format.SequenceEqual(WaveFourCC))
622-
{
623-
return "audio/wav";
624-
}
619+
if (format.SequenceEqual(WaveFourCC))
620+
{
621+
return "audio/wav";
625622
}
626623
}
627624

628-
if (header.Length >= 12 && header.Slice(4, Math.Min(4, header.Length - 4)).SequenceEqual(FtypFourCC))
625+
if (header.Length >= 12 && header.Slice(4, 4).SequenceEqual(FtypFourCC))
629626
{
630-
if (header.Length >= 12)
627+
var brand = header.Slice(8, 4);
628+
if (IsMp4Brand(brand))
631629
{
632-
var brand = header.Slice(8, Math.Min(4, header.Length - 8));
633-
if (IsMp4Brand(brand))
634-
{
635-
return "video/mp4";
636-
}
630+
return "video/mp4";
631+
}
637632

638-
if (brand.SequenceEqual(QuickTimeBrand))
639-
{
640-
return "video/quicktime";
641-
}
633+
if (brand.SequenceEqual(QuickTimeBrand))
634+
{
635+
return "video/quicktime";
642636
}
643637
}
644638

0 commit comments

Comments
 (0)