[Repo Assist] Fix #748: HTML-encode XML doc text nodes and unresolved cref values#994
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
- HTML-encode text nodes in readXmlElementAsHtml to prevent HTML injection when XML doc text contains characters like '<', '>', '&' - HTML-encode unresolved <see cref> values (the commented-out crefAsHtml code was already there, just never enabled) - Update test to expect HTML-encoded output for math expressions with '<' and '>' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
✅ Pull request created: #994 |
This was referenced Feb 23, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Closes #748
Summary
This PR fixes two related HTML-encoding gaps in
GenerateModel.fsthat could cause broken output or HTML injection when XML documentation comments contain special characters.Root Cause
In
readXmlElementAsHtml, two code paths were appending content to the HTML output without proper HTML encoding:Text nodes (line 1901):
html.Append(text)— if XML doc text contains<,>, or&characters (e.g. in LaTeX math like\[ 1 < 2 < 3 > 0 \]), these would be emitted as raw HTML characters, breaking the document structure.Unresolved
(see cref)values (line 1945):html.Append(cref.Value)— unresolved cross-references fall back to emitting the raw cref string (e.g.T:TheNamespace.GenericClass2\1), which was already noted in the code with a commented-outHtmlEncode` call.Fix
html.Append(HttpUtility.HtmlEncode text)let crefAsHtml = HttpUtility.HtmlEncode cref.ValueTrade-offs
HTML entities in the source XML doc (like
<) are decoded by the XML parser before being stored as text node values. My encoding re-encodes them correctly for HTML output. Browsers decode HTML entities before passing text to MathJax (which reads from the DOM), so LaTeX math with<and>operators continues to work correctly.The existing test for LaTeX math content was updated to expect the correctly HTML-encoded output (
1 < 2 < 3 > 0instead of1 < 2 < 3 > 0).Test Status
dotnet build src/FSharp.Formatting.ApiDocs/— succeeded (0 errors)dotnet test tests/FSharp.ApiDocs.Tests/— 68/68 passed (4 skipped, 0 failed)