Skip to content

Commit 6687d19

Browse files
committed
Remove ".."
1 parent 8564b1f commit 6687d19

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/AssetManagementBase.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageLicenseExpression>MIT</PackageLicenseExpression>
77
<PackageProjectUrl>https://github.com/rds1983/AssetManagementBase</PackageProjectUrl>
88
<TargetFramework>netstandard2.0</TargetFramework>
9-
<Version>0.6.4</Version>
9+
<Version>0.6.5</Version>
1010
</PropertyGroup>
1111

1212
<PropertyGroup Condition="'$(Configuration)'=='Release'">

src/AssetManager.cs

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Reflection;
4+
using System.Text;
45

56
namespace AssetManagementBase
67
{
@@ -92,6 +93,31 @@ private string BuildFullPath(string assetName)
9293
assetName = assetName.Replace('\\', SeparatorSymbol);
9394
assetName = CombinePath(_currentFolder, assetName);
9495

96+
if (assetName.Contains(".."))
97+
{
98+
// Remove ".."
99+
var parts = assetName.Split(SeparatorSymbol);
100+
var sb = new StringBuilder();
101+
sb.Append(SeparatorSymbol);
102+
103+
var partsStack = new List<string>();
104+
for(var i = 0; i < parts.Length; i++)
105+
{
106+
if (parts[i] == "..")
107+
{
108+
if (partsStack.Count > 0)
109+
{
110+
partsStack.RemoveAt(partsStack.Count - 1);
111+
}
112+
} else if (!string.IsNullOrEmpty(parts[i]))
113+
{
114+
partsStack.Add(parts[i]);
115+
}
116+
}
117+
118+
assetName = SeparatorSymbol + (string.Join(SeparatorString, partsStack));
119+
}
120+
95121
return assetName;
96122
}
97123

0 commit comments

Comments
 (0)