Skip to content

Commit 7aec5a2

Browse files
committed
Fix FileSystem.Combine when directory name is contained twice
1 parent cd06c7d commit 7aec5a2

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

Core.Common.Standard.Tests/KY.Core.Common.Standard.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
</ItemGroup>
5151
<ItemGroup>
5252
<Compile Include="ObjectExtensionTests.cs" />
53+
<Compile Include="PathHelperTests.cs" />
5354
<Compile Include="Properties\AssemblyInfo.cs" />
5455
</ItemGroup>
5556
<ItemGroup>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using KY.Core.DataAccess;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace KY.Core.Common.Standard.Tests
5+
{
6+
[TestClass]
7+
public class PathHelperTests
8+
{
9+
[TestMethod]
10+
public void TestCombineWithRelativePathAndDuplicateDirectoryName()
11+
{
12+
PathHelper pathHelper = new PathHelper();
13+
string result = pathHelper.Combine(@"C:\One\Two\Three\Two", "../Four");
14+
Assert.AreEqual(@"C:\One\Two\Three\Four", result);
15+
}
16+
17+
}
18+
}

Core.Common.Standard/DataAccess/PathHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class PathHelper
1818
private static readonly Regex absolutePathRegex = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
1919
? new Regex(@"^(([A-z]:)|(file:\\\\)|(\\\\))")
2020
: new Regex("^/");
21+
2122
public string Root { get; }
2223

2324
public PathHelper(string root = null)
@@ -98,10 +99,10 @@ public string Combine(params string[] pathChunks)
9899
}
99100
else if (isDrive && parts.Count > 1 || !isDrive && parts.Count > 0)
100101
{
101-
parts.Remove(last);
102+
parts.RemoveAt(parts.Count - 1);
102103
}
103104
}
104-
else if (parts.Count == 0 ||last == parentSymbol)
105+
else if (parts.Count == 0 || last == parentSymbol)
105106
{
106107
parts.Add(chunk);
107108
}

Core.Common.Standard/KY.Core.Common.Standard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<RootNamespace>KY.Core</RootNamespace>
66
<AssemblyName>KY.Core.Common</AssemblyName>
7-
<Version>4.17.0</Version>
7+
<Version>4.18.0</Version>
88
<Authors>KY-Programming</Authors>
99
<Company>KY-Programmingp</Company>
1010
<Product>KY.Core</Product>

0 commit comments

Comments
 (0)