Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Fix NormalizePath and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Jan 1, 2022
1 parent 377fac4 commit b328456
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Squirrel/Internal/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public static string RemoveByteOrderMarkerIfPresent(byte[] content)

public static string NormalizePath(string path)
{
return Path.GetFullPath(new Uri(path).LocalPath)
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var fullPath = Path.GetFullPath(path);
var normalized = new Uri(fullPath, UriKind.Absolute).LocalPath;
return normalized.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}

public static bool IsFileInDirectory(string file, string directory)
Expand Down
32 changes: 31 additions & 1 deletion test/UtilityTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -14,6 +14,36 @@ namespace Squirrel.Tests.Core
{
public class UtilityTests : IEnableLogger
{
[Theory]
[InlineData("file.txt", "file.txt")]
[InlineData("file", "file")]
[InlineData("/file", "\\file")]
[InlineData("/file/", "\\file")]
[InlineData("one\\two\\..\\file", "one\\file")]
[InlineData("C:/AnApp/file/", "C:\\AnApp\\file")]
public void PathIsNormalized(string input, string expected)
{
var exp = Path.GetFullPath(expected);
var normal = Utility.NormalizePath(input);
Assert.Equal(exp, normal);
}

[Theory]
[InlineData("C:\\AnApp", "C:\\AnApp\\file.exe", true)]
[InlineData("C:\\AnApp\\", "C:\\AnApp\\file.exe", true)]
[InlineData("C:\\AnApp", "C:\\AnApp\\sub\\dir\\file.exe", true)]
[InlineData("C:\\AnApp\\", "C:\\AnApp\\sub\\dir\\file.exe", true)]
[InlineData("C:\\AnAppTwo", "C:\\AnApp\\file.exe", false)]
[InlineData("C:\\AnAppTwo\\", "C:\\AnApp\\file.exe", false)]
[InlineData("C:\\AnAppTwo", "C:\\AnApp\\sub\\dir\\file.exe", false)]
[InlineData("C:\\AnAppTwo\\", "C:\\AnApp\\sub\\dir\\file.exe", false)]
[InlineData("AnAppThree", "AnAppThree\\file.exe", true)]
public void FileIsInDirectory(string directory, string file, bool isIn)
{
var fileInDir = Utility.IsFileInDirectory(file, directory);
Assert.Equal(isIn, fileInDir);
}

[Fact]
public void SetAppIdOnShortcutTest()
{
Expand Down

0 comments on commit b328456

Please sign in to comment.