Move Path and File validation to Shared Utilities
Created extension methods: IsPathValid(Folder) IsFileValid(File) IsPathOrFileValid(string) Added client side validation check for Folders.
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using File = Oqtane.Models.File;
|
||||
|
||||
namespace Oqtane.Shared
|
||||
{
|
||||
@ -254,5 +256,22 @@ namespace Oqtane.Shared
|
||||
|
||||
return Path.Combine(segments).TrimEnd();
|
||||
}
|
||||
|
||||
public static bool IsPathValid(this Folder folder)
|
||||
{
|
||||
return IsPathOrFileValid(folder.Name);
|
||||
}
|
||||
|
||||
public static bool IsFileValid(this File file)
|
||||
{
|
||||
return IsPathOrFileValid(file.Name);
|
||||
}
|
||||
|
||||
public static bool IsPathOrFileValid(this string name)
|
||||
{
|
||||
return (name.IndexOfAny(Constants.InvalidFileNameChars) == -1 &&
|
||||
!Constants.InvalidFileNameEndingChars.Any(name.EndsWith) &&
|
||||
!Constants.ReservedDevices.Split(',').Contains(name.ToUpper().Split('.')[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user