Browse Source

Added handling for empty extension parameters in ImageFormatManager.TryFindFormatByFileExtension

pull/2386/head
oliver@citruslime.com 4 years ago
parent
commit
ba57cf3f5c
  1. 3
      src/ImageSharp/Formats/ImageFormatManager.cs

3
src/ImageSharp/Formats/ImageFormatManager.cs

@ -101,11 +101,14 @@ public class ImageFormatManager
/// </param> /// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns> /// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
public bool TryFindFormatByFileExtension(string extension, [NotNullWhen(true)] out IImageFormat? format) public bool TryFindFormatByFileExtension(string extension, [NotNullWhen(true)] out IImageFormat? format)
{
if (!string.IsNullOrWhiteSpace(extension))
{ {
if (extension[0] == '.') if (extension[0] == '.')
{ {
extension = extension[1..]; extension = extension[1..];
} }
}
format = this.imageFormats.FirstOrDefault(x => format = this.imageFormats.FirstOrDefault(x =>
x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)); x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));

Loading…
Cancel
Save