From e96f4e3a26c067008e222c1633e6c4355c926566 Mon Sep 17 00:00:00 2001 From: Richard Edwards Date: Fri, 28 Jun 2024 13:17:21 +0100 Subject: [PATCH] Fixes Updated version to 6.0.0-preview-0318 --- .../Mime/MimeTypeUtility.cs | 31 ++++++++++++++++++- Directory.Build.props | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Core/src/Umbrella.Utilities/Mime/MimeTypeUtility.cs b/Core/src/Umbrella.Utilities/Mime/MimeTypeUtility.cs index d4fb14126..6d06c73f4 100644 --- a/Core/src/Umbrella.Utilities/Mime/MimeTypeUtility.cs +++ b/Core/src/Umbrella.Utilities/Mime/MimeTypeUtility.cs @@ -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; @@ -35,7 +36,35 @@ public string GetMimeType(string fileNameOrExtension) try { - return MimeTypes.GetMimeType(fileNameOrExtension); + ReadOnlySpan span = fileNameOrExtension.AsSpan().Trim(); + Span destinationSpan = stackalloc char[span.Length]; + span.ToLowerInvariantSlim(destinationSpan); + + int idxPeriod = destinationSpan.IndexOf('.'); + + if (destinationSpan.IndexOf('.') is -1) + { + Span 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 })) { diff --git a/Directory.Build.props b/Directory.Build.props index c06620c5a..c395e51ce 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 6.0.0-preview-0317 + 6.0.0-preview-0318 enable nullable