-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: InvalidInputFile error occurs if file contains URI escaped chara…
…cters
- Loading branch information
Showing
2 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Docfx.Common.Tests; | ||
|
||
public class PathUtilityTest | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.AdditionalTests), MemberType = typeof(TestData), DisableDiscoveryEnumeration = false)] | ||
public void TestMakeRelativePath(string basePath, string targetPath, string expected) | ||
{ | ||
// Act | ||
var result = PathUtility.MakeRelativePath(basePath, targetPath); | ||
|
||
// Assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(TestData.EscapedPaths), MemberType = typeof(TestData), DisableDiscoveryEnumeration = true)] | ||
public void TestMakeRelativePathWithEncodedPath(string inputPath) | ||
{ | ||
// Arrange | ||
string basePath = "./"; | ||
var expected = inputPath; | ||
|
||
// Act | ||
var result = PathUtility.MakeRelativePath(basePath, inputPath); | ||
|
||
// Assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
private static class TestData | ||
{ | ||
public static TheoryData<string, string, string> AdditionalTests = new() | ||
{ | ||
{ @"/a/b/d", @"/a/b/file.md", @"../file.md"}, // root relative path | ||
{ @"~/a/b/d", @"~/a/b/file.md", @"../file.md"}, // user home directory relative path | ||
{ @"./", @"\\UNCPath\file.md", @"//UNCPath/file.md"}, // UNC path | ||
{ @"./", @"file:///C:/temp/test.md", @"file:/C:/temp/test.md"}, // `file:` Uri path | ||
{ @"file:///C:/temp", @"file:///C:/temp/test.md", @"test.md"}, // `file:` Uri relative path | ||
{ @"/temp/dir", @"/temp/dir/subdir/", @"subdir/"}, // If target path endsWith directory separator char. resolved path should contain directory separator. | ||
}; | ||
|
||
public static TheoryData<string> EscapedPaths = new() | ||
{ | ||
"EscapedHypen(%2D).md", // Contains escaped hypen char | ||
"EscapedSpace(%20)_with_NonAsciiChar(α).md", // Contains escaped space char and non-unicode char | ||
}; | ||
} | ||
} |