mirror of https://github.com/abpframework/abp.git
4 changed files with 56 additions and 101 deletions
@ -1,82 +0,0 @@ |
|||
//using System;
|
|||
//using System.Linq;
|
|||
//using JetBrains.Annotations;
|
|||
//using Microsoft.Extensions.FileProviders;
|
|||
//using Microsoft.Extensions.Primitives;
|
|||
|
|||
//namespace Volo.Abp.VirtualFileSystem
|
|||
//{
|
|||
// //TODO: Ensure that merging such subfolders is secure! (anyone can add /.. to the beginning!)..?
|
|||
|
|||
// public class FileProviderSubFolderWrapper : IFileProvider
|
|||
// {
|
|||
// private readonly IFileProvider _fileProvider;
|
|||
// private readonly string _rootPath;
|
|||
// private readonly string[] _allowedExtraFolders;
|
|||
// private readonly string[] _allowedExtraFileExtensions;
|
|||
|
|||
// public FileProviderSubFolderWrapper(
|
|||
// IFileProvider fileProvider,
|
|||
// string rootPath,
|
|||
// string[] allowedExtraFolders = null,
|
|||
// string[] allowedExtraFileExtensions = null)
|
|||
// {
|
|||
// _fileProvider = fileProvider;
|
|||
// _rootPath = rootPath;
|
|||
// _allowedExtraFileExtensions = allowedExtraFileExtensions ?? Array.Empty<string>();
|
|||
// _allowedExtraFolders = allowedExtraFolders ?? Array.Empty<string>();
|
|||
// }
|
|||
|
|||
// public IFileInfo GetFileInfo(string subpath)
|
|||
// {
|
|||
// Check.NotNullOrEmpty(subpath, nameof(subpath));
|
|||
|
|||
// if (ExtraAllowedPath(subpath))
|
|||
// {
|
|||
// var fileInfo = _fileProvider.GetFileInfo(subpath);
|
|||
// if (fileInfo.Exists)
|
|||
// {
|
|||
// return fileInfo;
|
|||
// }
|
|||
// }
|
|||
|
|||
// return _fileProvider.GetFileInfo(_rootPath + subpath);
|
|||
// }
|
|||
|
|||
// public IDirectoryContents GetDirectoryContents([NotNull] string subpath)
|
|||
// {
|
|||
// Check.NotNullOrEmpty(subpath, nameof(subpath));
|
|||
|
|||
// if (ExtraAllowedPath(subpath))
|
|||
// {
|
|||
// var directory = _fileProvider.GetDirectoryContents(subpath);
|
|||
// if (directory.Exists)
|
|||
// {
|
|||
// return directory;
|
|||
// }
|
|||
// }
|
|||
|
|||
// return _fileProvider.GetDirectoryContents(_rootPath + subpath);
|
|||
// }
|
|||
|
|||
// private bool ExtraAllowedPath(string path)
|
|||
// {
|
|||
// return ExtraAllowedFolder(path) && ExtraAllowedExtension(path);
|
|||
// }
|
|||
|
|||
// private bool ExtraAllowedFolder(string path)
|
|||
// {
|
|||
// return _allowedExtraFolders.Any(s => path.StartsWith(s, StringComparison.OrdinalIgnoreCase));
|
|||
// }
|
|||
|
|||
// private bool ExtraAllowedExtension(string path)
|
|||
// {
|
|||
// return _allowedExtraFileExtensions.Any(e => path.EndsWith(e, StringComparison.OrdinalIgnoreCase));
|
|||
// }
|
|||
|
|||
// public IChangeToken Watch(string filter)
|
|||
// {
|
|||
// return _fileProvider.Watch(filter); //TODO: Why this does not use NormalizePath?
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -0,0 +1,41 @@ |
|||
using System.IO; |
|||
using Microsoft.Extensions.Primitives; |
|||
|
|||
namespace Volo.Abp.AspNetCore.VirtualFileSystem |
|||
{ |
|||
/* Inspired from the Microsoft.Extensions.FileProviders.Physical package. */ |
|||
internal static class PathUtils |
|||
{ |
|||
private static readonly char[] PathSeparators = {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}; |
|||
|
|||
public static bool PathNavigatesAboveRoot(string path) |
|||
{ |
|||
var tokenizer = new StringTokenizer(path, PathSeparators); |
|||
var depth = 0; |
|||
|
|||
foreach (var segment in tokenizer) |
|||
{ |
|||
if (segment.Equals(".") || segment.Equals("")) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
if (segment.Equals("..")) |
|||
{ |
|||
depth--; |
|||
|
|||
if (depth == -1) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
depth++; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue