fix: parse HTML instead of XML in SvgCanvas2D.convertHtml - #1012
Conversation
The method was incorrectly using `parseXml` (XML parser) instead of `DOMParser` with `text/html`. This bug was introduced in commit 2f4bb07 while trying to share code between methods — the code wasn't actually the same. - Use `DOMParser.parseFromString(val, 'text/html')` for correct HTML parsing - Add tests for `convertHtml` covering plain text, nested HTML, malformed HTML, empty input, and body tag extraction - Improve JSDoc of the `text` method
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
WalkthroughSwitches SvgCanvas2D.convertHtml to parse HTML using DOMParser('text/html'), adds unit tests for convertHtml across multiple scenarios, and updates minor JSDoc formatting and testing guidance in docs. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/core/__tests__/view/canvas/SvgCanvas2D.test.ts (1)
17-22: Import extension issue from previous review is now resolved.The barrel import
from '../../../src'correctly omits the.jsextension, in line with the moduleNameMapper convention for test files.
🧹 Nitpick comments (1)
packages/core/__tests__/view/canvas/SvgCanvas2D.test.ts (1)
41-44: Global.trim()slightly weakens the "plain text unchanged" assertion.
.trim()on every case means the'plain text unchanged if not valid HTML'test would still pass even ifconvertHtmlreturned' plain text ', making the test name misleading. It's only strictly needed for the whitespace case (Line 40).Consider scoping the trim to only the cases that require it, or splitting the whitespace case into its own
testblock:♻️ Proposed refinement
- ])('%s', (_description, input, expected) => { - const canvas = createSvgCanvas2D(); - expect(canvas.convertHtml(input).trim()).toBe(expected); - }); + ])('%s', (_description, input, expected) => { + const canvas = createSvgCanvas2D(); + expect(canvas.convertHtml(input)).toBe(expected); + });And update the whitespace test case's expected value to account for leading/trailing whitespace from the parsed result (or keep the trim only in a dedicated test):
test('HTML with whitespace trims surrounding whitespace', () => { const canvas = createSvgCanvas2D(); expect(canvas.convertHtml(' <div> spaced </div> ').trim()).toBe('<div> spaced </div>'); });
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CLAUDE.mdpackages/core/__tests__/view/canvas/SvgCanvas2D.test.ts
✅ Files skipped from review due to trivial changes (1)
- CLAUDE.md
|



The method was incorrectly using
parseXml(XML parser) instead ofDOMParserwithtext/html.This bug was introduced in commit 2f4bb07 while trying to share code between methods — the code wasn't actually the same.
DOMParser.parseFromString(val, 'text/html')for correct HTML parsingconvertHtmlcovering plain text, nested HTML, malformedHTML, empty input, and body tag extraction
textmethodSummary by CodeRabbit
Tests
Bug Fixes
Documentation