Properly fixes: U4-4893 Inconsistent display of file extensions in the UI

This commit is contained in:
Shannon
2014-06-18 17:11:47 +10:00
parent f25463babe
commit 56111be82d
10 changed files with 44 additions and 31 deletions

View File

@@ -40,6 +40,25 @@ namespace Umbraco.Core
ToCSharpEscapeChars[escape[0]] = escape[1];
}
internal static string StripFileExtension(this string fileName)
{
//filenames cannot contain line breaks
if (fileName.Contains(Environment.NewLine) || fileName.Contains("\r") || fileName.Contains("\n")) return fileName;
var lastIndex = fileName.LastIndexOf('.');
if (lastIndex > 0)
{
var ext = fileName.Substring(lastIndex);
//file extensions cannot contain whitespace
if (ext.Contains(" ")) return fileName;
return string.Format("{0}", fileName.Substring(0, fileName.IndexOf(ext, StringComparison.Ordinal)));
}
return fileName;
}
/// <summary>
/// This tries to detect a json string, this is not a fail safe way but it is quicker than doing
/// a try/catch when deserializing when it is not json.