Fix for exception throw when validating URLs (#7701)

This commit is contained in:
Joe Delly
2020-03-24 13:35:11 -04:00
committed by GitHub
parent ffef6ed2a1
commit 2ec0861051
3 changed files with 34 additions and 1 deletions

View File

@@ -79,6 +79,21 @@ namespace Umbraco.Core
}
/// <summary>
/// Determines the extension of the path or URL
/// </summary>
/// <param name="file"></param>
/// <returns>Extension of the file</returns>
public static string GetFileExtension(this string file)
{
//Find any characters between the last . and the start of a query string or the end of the string
const string pattern = @"(?<extension>\.[^\.\?]+)(\?.*|$)";
var match = Regex.Match(file, pattern);
return match.Success
? match.Groups["extension"].Value
: string.Empty;
}
/// <summary>
/// Based on the input string, this will detect if the string is a JS path or a JS snippet.
/// If a path cannot be determined, then it is assumed to be a snippet the original text is returned