Fixed validation of fileextension.
This commit is contained in:
committed by
Sebastiaan Janssen
parent
ad121bd758
commit
90d591e5a8
@@ -99,7 +99,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
// process the file
|
||||
// no file, invalid file, reject change
|
||||
if (UploadFileTypeValidator.ValidateFileExtension(file.FileName) == false)
|
||||
if (UploadFileTypeValidator.IsValidFileExtension(file.FileName) == false)
|
||||
return null;
|
||||
|
||||
// get the filepath
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
// process the file
|
||||
// no file, invalid file, reject change
|
||||
if (UploadFileTypeValidator.ValidateFileExtension(file.FileName) == false)
|
||||
if (UploadFileTypeValidator.IsValidFileExtension(file.FileName) == false)
|
||||
return null;
|
||||
|
||||
// get the filepath
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Web.Composing;
|
||||
@@ -16,13 +16,27 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
public IEnumerable<ValidationResult> Validate(object value, string valueType, object dataTypeConfiguration)
|
||||
{
|
||||
if (!(value is JObject jobject) || jobject["selectedFiles"] == null) yield break;
|
||||
|
||||
var fileNames = jobject["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var fileName in fileNames)
|
||||
string selectedFiles = null;
|
||||
if (value is JObject jobject && jobject["selectedFiles"] is JToken jToken)
|
||||
{
|
||||
if (ValidateFileExtension(fileName) == false)
|
||||
selectedFiles = jToken.ToString();
|
||||
}
|
||||
else if (valueType?.InvariantEquals(ValueTypes.String) == true)
|
||||
{
|
||||
selectedFiles = value as string;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(selectedFiles))
|
||||
yield break;
|
||||
}
|
||||
|
||||
var fileNames = selectedFiles?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (fileNames == null || !fileNames.Any())
|
||||
yield break;
|
||||
|
||||
foreach (string filename in fileNames)
|
||||
{
|
||||
if (IsValidFileExtension(filename) == false)
|
||||
{
|
||||
//we only store a single value for this editor so the 'member' or 'field'
|
||||
// we'll associate this error with will simply be called 'value'
|
||||
@@ -30,11 +44,11 @@ namespace Umbraco.Web.PropertyEditors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool ValidateFileExtension(string fileName)
|
||||
|
||||
internal static bool IsValidFileExtension(string fileName)
|
||||
{
|
||||
if (fileName.IndexOf('.') <= 0) return false;
|
||||
var extension = Path.GetExtension(fileName).TrimStart(".");
|
||||
var extension = new FileInfo(fileName).Extension.TrimStart(".");
|
||||
return Current.Configs.Settings().Content.IsFileAllowedForUpload(extension);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user