From 006445df03bae6578060623e4954851f2ccba2bc Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Mar 2020 18:22:03 +1000 Subject: [PATCH] MimeType - Add extra checking to Cef.GetMimeType Also update the ResourceHandler.FromFilePath xml doc to reference Cef.GetMimeType Issue #3041 --- CefSharp.Core/Cef.h | 6 ++++++ CefSharp/ResourceHandler.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 48a7f6e32..48c95c070 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -763,10 +763,16 @@ namespace CefSharp /// Returns the mime type for the specified file extension or an empty string if unknown. static String^ GetMimeType(String^ extension) { + if (extension == nullptr) + { + throw gcnew ArgumentNullException("extension"); + } + if (extension->StartsWith(".")) { extension = extension->Substring(1, extension->Length - 1); } + return StringUtils::ToClr(CefGetMimeType(StringUtils::ToNative(extension))); } diff --git a/CefSharp/ResourceHandler.cs b/CefSharp/ResourceHandler.cs index 3bb3afc06..698109385 100644 --- a/CefSharp/ResourceHandler.cs +++ b/CefSharp/ResourceHandler.cs @@ -258,7 +258,7 @@ namespace CefSharp } /// - /// Gets the resource from the file path specified. Use the + /// Gets the resource from the file path specified. Use the Cef.GetMimeType() /// helper method to lookup the mimeType if required. Uses CefStreamResourceHandler for reading the data /// /// Location of the file.