Skip to content

Commit

Permalink
Fix for rooted paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Oct 26, 2023
1 parent 097b0f7 commit 1659ab9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AssetManagementBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/rds1983/AssetManagementBase</PackageProjectUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.6.6</Version>
<Version>0.6.7</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
18 changes: 11 additions & 7 deletions src/AssetManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AssetManagementBase.Utility;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -96,8 +97,13 @@ public T UseLoader<T>(AssetLoader<T> loader, string assetName, IAssetSettings se

private string BuildFullPath(string assetName)
{
var isRooted = assetName.IsPathRooted2();
assetName = assetName.Replace('\\', SeparatorSymbol);
assetName = CombinePath(_currentFolder, assetName);

if (!isRooted)
{
assetName = CombinePath(_currentFolder, assetName);
}

if (assetName.Contains(".."))
{
Expand All @@ -109,12 +115,10 @@ private string BuildFullPath(string assetName)
var partsStack = new List<string>();
for(var i = 0; i < parts.Length; i++)
{
if (parts[i] == "..")
if (parts[i] == ".." && partsStack.Count > 0 &&
partsStack[partsStack.Count - 1] != ".." && partsStack[partsStack.Count - 1] != ".")
{
if (partsStack.Count > 0)
{
partsStack.RemoveAt(partsStack.Count - 1);
}
partsStack.RemoveAt(partsStack.Count - 1);
} else if (!string.IsNullOrEmpty(parts[i]))
{
partsStack.Add(parts[i]);
Expand Down
8 changes: 7 additions & 1 deletion src/FileAssetAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AssetManagementBase.Utility;
using System;
using System.IO;

namespace AssetManagementBase
Expand Down Expand Up @@ -41,6 +42,11 @@ private string BuildFullPath(string assetName)
assetName = assetName.Replace(AssetManager.SeparatorSymbol, Path.DirectorySeparatorChar);
}

if (assetName.IsPathRooted2())
{
return assetName;
}

// Asset name should always have directory separator at the start
// While base folder shouldnt
// Hence such combine should work
Expand Down
14 changes: 14 additions & 0 deletions src/Utility/PathUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.IO;

namespace AssetManagementBase.Utility
{
internal static class PathUtils
{
public static bool IsPathRooted2(this string path)
{
var drive = Path.GetPathRoot(path);

return !string.IsNullOrEmpty(drive) && drive[0] != '/' && drive[0] != '\\';
}
}
}

0 comments on commit 1659ab9

Please sign in to comment.