Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,38 @@ type ReturnValue = number;
}
`);
});

it('should not double-unescape HTML entities in inline code', async () => {
// `&amp;lt;` must decode to `&lt;` (single unescape), not `<`.
const markdown = `### Button

**Button Props:**

| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| name | \`&amp;lt;T&amp;gt;\` | - | - |
`;

const result = await parseTypesMarkdown(markdown);
const componentMeta = (result.exports.Button.type as { data: ComponentTypeMeta }).data;
expect(componentMeta.props.name.typeText).toBe('&lt;T&gt;');
});
Comment on lines +1623 to +1637

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a second test case in commit 7e25cb0 that asserts &amp;amp;lt;T&amp;amp;gt; decodes to &amp;lt;T&amp;gt; (only one level of &amp; unescaped), covering the double-encoded pattern mentioned in the feedback.


it('should not double-unescape double-encoded HTML entities in inline code', async () => {
// `&amp;amp;lt;` must decode to `&amp;lt;` (single unescape of &amp;), not `&lt;` or `<`.
const markdown = `### Button

**Button Props:**

| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| name | \`&amp;amp;lt;T&amp;amp;gt;\` | - | - |
`;

const result = await parseTypesMarkdown(markdown);
const componentMeta = (result.exports.Button.type as { data: ComponentTypeMeta }).data;
expect(componentMeta.props.name.typeText).toBe('&amp;lt;T&amp;gt;');
});
});

describe('typeNameMap parsing', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ interface VariantData {

/**
* Decode HTML entities commonly found in markdown.
* `&amp;` is unescaped LAST to avoid double-unescaping inputs like `&amp;lt;`,
* which should decode to `&lt;` rather than `<`.
*/
function decodeHtmlEntities(text: string): string {
return text
.replace(/&quot;/g, '"')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&#39;/g, "'")
.replace(/&apos;/g, "'")
.replace(/&amp;/g, '&')
.replace(/“/g, '"') // Left double quote
.replace(/”/g, '"'); // Right double quote
}
Expand Down
Loading