Skip to content

Fix xdoc generator to HTML-escape content of {@code} and {@literal} tags - #619

Open
gnodet wants to merge 1 commit into
codehaus-plexus:masterfrom
gnodet:fix/xdoc-code-tag-escaping
Open

gnodet wants to merge 1 commit into
codehaus-plexus:masterfrom
gnodet:fix/xdoc-code-tag-escaping

Conversation

@gnodet

@gnodet gnodet commented Oct 23, 2026

Copy link
Copy Markdown
Member

Problem

The chhorz javadoc-parser wraps {@code X} content verbatim in <code>X</code> without HTML-escaping X. When X contains angle brackets (e.g. {@code <element>}), Jsoup subsequently parses <element> as an unknown HTML tag and silently drops it from the XML output — the tag name disappears from the generated site.

This is the root cause of apache/maven#13675, where descriptions such as:

  • {@code <activeProfiles>}
  • {@code <activation>}
  • {@code <name>value</name>}

all render with the angle-bracket content missing on the published Maven site.

Root cause trace

In XdocGenerator.rewrite():

  1. The MXParser XML parser reads a <description> outside CDATA and decodes &lt; → <. So {@code &lt;element&gt;} in the .mdo file becomes {@code <element>} in the description string.
  2. The javadoc-parser produces <code><element></code> — the content is not HTML-escaped.
  3. Jsoup, in XML output mode, treats <element> as an unknown element and drops it silently.

Fix

Pre-process {@code} and {@literal} inline tags in XdocGenerator.rewrite() to HTML-escape their content before the javadoc-parser and Jsoup pipeline see it.

The escapeHtml() helper normalises pre-existing &lt;/&gt; entities first (which appear in CDATA-wrapped .mdo descriptions) so both forms are handled correctly and produce identical correct output:

  • {@code <element>} (XML-decoded) → <code>&lt;element&gt;</code> ✓
  • {@code &lt;element&gt;} (from CDATA) → <code>&lt;element&gt;</code> ✓

Test

Added a field with {@code &lt;name&gt;value&lt;/name&gt;} (outside CDATA, so MXParser decodes it to {@code <name>value</name>}) to html4.mdo and verified the expected output <code>&lt;name&gt;value&lt;/name&gt;</code> in html4.expected.xml.

The chhorz javadoc-parser wraps {@code X} content verbatim in <code>X</code>
without HTML-escaping X. When X contains angle brackets (e.g. {@code <element>}),
Jsoup subsequently parses <element> as an unknown HTML tag and silently drops it
from the XML output, causing the tag name to disappear from the generated site.

This is visible in Maven's settings reference where descriptions such as
  {@code <activeProfiles>}  and  {@code <activation>}
rendered with the tag name missing on the published site.

Fix: pre-process {@code} and {@literal} inline tags in XdocGenerator.rewrite()
by HTML-escaping their content before the javadoc-parser and Jsoup pipeline see
it. The escapeHtml() helper normalises pre-existing &lt;/&gt; entities first
(which appear in CDATA-wrapped .mdo descriptions) so both forms are handled
correctly and produce identical output.

Add a test case to html4.mdo / html4.expected.xml that exercises the fix with
{@code &lt;name&gt;value&lt;/name&gt;} (decoded to {@code <name>value</name>}
by MXParser) and verifies <code>&lt;name&gt;value&lt;/name&gt;</code> in output.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant