Skip to content

Commit

Permalink
fix: handle encoded url in relative path (dotnet#5223)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharanya-rao authored and superyyrrzz committed Oct 24, 2019
1 parent 7010df7 commit 7784443
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Microsoft.DocAsCode.Common/Path/RelativePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ private static RelativePath TryParseCore(string path, bool throwOnError)
switch (parts[i])
{
case "~":
case "%7E":
if (parentCount > 0 || stack.Count > 0 || isFromWorkingFolder)
{
throw new InvalidOperationException($"Invalid path: {path}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ public override void Dispose()
base.Dispose();
}

[Fact]
public void ProcessMarkdownResultWithEncodedUrlShouldSucceed()
[Theory]
[InlineData(@"<p><a href=""%7E/docs/csharp/language-reference/keywords/select-clause.md""></p>", "~/docs/csharp/language-reference/keywords/select-clause.md")]
[InlineData(@"<p><a href=""%7E/../samples/readme.md""></p>", "~/../samples/readme.md")]
public void ProcessMarkdownResultWithEncodedUrlShouldSucceed(string htmlContent, string expectedFileLink)
{
var markdownResult = new MarkupResult
{
Html = @"<p><a href=""%7E/docs/csharp/language-reference/keywords/select-clause.md""></p>"
Html = htmlContent
};

markdownResult = MarkupUtility.Parse(markdownResult, "docs/framework/data/wcf/how-to-project-query-results-wcf-data-services.md", ImmutableDictionary.Create<string, FileAndType>());
Assert.Equal("~/docs/csharp/language-reference/keywords/select-clause.md", markdownResult.LinkToFiles.First());
Assert.Equal(expectedFileLink, markdownResult.LinkToFiles.First());
}

[Fact]
Expand Down

0 comments on commit 7784443

Please sign in to comment.