Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Warnings that occurs when bookmark link contains non-ASCII chars #9660

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading