Skip to content

Commit 1659ab9

Browse files
committed
Fix for rooted paths
1 parent 097b0f7 commit 1659ab9

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
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.6</Version>
9+
<Version>0.6.7</Version>
1010
</PropertyGroup>
1111

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

src/AssetManager.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using AssetManagementBase.Utility;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Reflection;
@@ -96,8 +97,13 @@ public T UseLoader<T>(AssetLoader<T> loader, string assetName, IAssetSettings se
9697

9798
private string BuildFullPath(string assetName)
9899
{
100+
var isRooted = assetName.IsPathRooted2();
99101
assetName = assetName.Replace('\\', SeparatorSymbol);
100-
assetName = CombinePath(_currentFolder, assetName);
102+
103+
if (!isRooted)
104+
{
105+
assetName = CombinePath(_currentFolder, assetName);
106+
}
101107

102108
if (assetName.Contains(".."))
103109
{
@@ -109,12 +115,10 @@ private string BuildFullPath(string assetName)
109115
var partsStack = new List<string>();
110116
for(var i = 0; i < parts.Length; i++)
111117
{
112-
if (parts[i] == "..")
118+
if (parts[i] == ".." && partsStack.Count > 0 &&
119+
partsStack[partsStack.Count - 1] != ".." && partsStack[partsStack.Count - 1] != ".")
113120
{
114-
if (partsStack.Count > 0)
115-
{
116-
partsStack.RemoveAt(partsStack.Count - 1);
117-
}
121+
partsStack.RemoveAt(partsStack.Count - 1);
118122
} else if (!string.IsNullOrEmpty(parts[i]))
119123
{
120124
partsStack.Add(parts[i]);

src/FileAssetAccessor.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using AssetManagementBase.Utility;
2+
using System;
23
using System.IO;
34

45
namespace AssetManagementBase
@@ -41,6 +42,11 @@ private string BuildFullPath(string assetName)
4142
assetName = assetName.Replace(AssetManager.SeparatorSymbol, Path.DirectorySeparatorChar);
4243
}
4344

45+
if (assetName.IsPathRooted2())
46+
{
47+
return assetName;
48+
}
49+
4450
// Asset name should always have directory separator at the start
4551
// While base folder shouldnt
4652
// Hence such combine should work

src/Utility/PathUtils.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.IO;
2+
3+
namespace AssetManagementBase.Utility
4+
{
5+
internal static class PathUtils
6+
{
7+
public static bool IsPathRooted2(this string path)
8+
{
9+
var drive = Path.GetPathRoot(path);
10+
11+
return !string.IsNullOrEmpty(drive) && drive[0] != '/' && drive[0] != '\\';
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)