Skip to content

Commit

Permalink
fix: Warnings that occurs when bookmark link contains non-ASCII chars (
Browse files Browse the repository at this point in the history
…#9660)

fix: warnings that occurs when bookmark link contains non-ascii chars
  • Loading branch information
filzrev authored Feb 10, 2024
1 parent 425cb59 commit 066818a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Docfx.Build/PostProcessors/ValidateBookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void HandleCore(HtmlDocument document, ManifestItem manifestI
{
Title = node.InnerText,
Href = TransformPath(outputFile, decodedLink),
Bookmark = bookmark,
Bookmark = Uri.UnescapeDataString(bookmark),
SourceFragment = WebUtility.HtmlDecode(node.GetAttributeValue("data-raw-source", null)),
SourceFile = WebUtility.HtmlDecode(node.GetAttributeValue("sourceFile", null)),
SourceLineNumber = node.GetAttributeValue("sourceStartLineNumber", 0),
Expand Down
35 changes: 35 additions & 0 deletions test/Docfx.Build.Tests/ValidateBookmarkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,39 @@ public void TestNoCheck()
var actual = logs.Select(l => Tuple.Create(l.Message, l.File)).ToList();
Assert.True(!expected.Except(actual).Any() && expected.Length == actual.Count);
}

[Fact]
public void TestLinkThatContainsNonAsciiChars()
{
Manifest manifest = new()
{
SourceBasePath = _outputFolder,
Files =
{
new ManifestItem { SourceRelativePath = "non_ascii.md", Output = { { ".html", new OutputFileInfo { RelativePath = "non_ascii.html" } } } },
}
};

File.WriteAllText(Path.Combine(_outputFolder, "non_ascii.html"), """
<h2 id="foo">foo</h2>
<p>Visit <a href="#qu%C3%A9bec">Québec</a>.</p>
<h2 id="québec">Québec</h2>
<p>The province or the city.</p>
""");

Logger.RegisterListener(_listener);
try
{
new HtmlPostProcessor
{
Handlers = { new ValidateBookmark() }
}.Process(manifest, _outputFolder);
}
finally
{
Logger.UnregisterListener(_listener);
}
var logs = _listener.Items;
Assert.Empty(logs);
}
}

0 comments on commit 066818a

Please sign in to comment.