Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Updated version to 6.0.0-preview-0318
  • Loading branch information
richieedwards committed Jun 28, 2024
1 parent 546793f commit e96f4e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion Core/src/Umbrella.Utilities/Mime/MimeTypeUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using MimeKit;
using Umbrella.Utilities.Exceptions;
using Umbrella.Utilities.Extensions;
using Umbrella.Utilities.Mime.Abstractions;

namespace Umbrella.Utilities.Mime;
Expand Down Expand Up @@ -35,7 +36,35 @@ public string GetMimeType(string fileNameOrExtension)

try
{
return MimeTypes.GetMimeType(fileNameOrExtension);
ReadOnlySpan<char> span = fileNameOrExtension.AsSpan().Trim();
Span<char> destinationSpan = stackalloc char[span.Length];
span.ToLowerInvariantSlim(destinationSpan);

int idxPeriod = destinationSpan.IndexOf('.');

if (destinationSpan.IndexOf('.') is -1)
{
Span<char> periodSpan = stackalloc char[span.Length + 1];
periodSpan[0] = '.';

for (int i = 1; i < periodSpan.Length; i++)
{
periodSpan[i] = destinationSpan[i - 1];
}

destinationSpan = periodSpan;
}
else
{
int idxLastPeriod = destinationSpan.LastIndexOf('.');

if (idxLastPeriod > 0)
{
destinationSpan = destinationSpan[idxLastPeriod..];
}
}

return MimeTypes.GetMimeType(destinationSpan.ToString());
}
catch (Exception exc) when (_logger.WriteError(exc, new { fileNameOrExtension }))
{
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>6.0.0-preview-0317</Version>
<Version>6.0.0-preview-0318</Version>

<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
Expand Down

0 comments on commit e96f4e3

Please sign in to comment.