Skip to content

Dom parser improvement#753

Merged
feruzm merged 3 commits intodevelopfrom
rren
Apr 11, 2026
Merged

Dom parser improvement#753
feruzm merged 3 commits intodevelopfrom
rren

Conversation

@feruzm
Copy link
Copy Markdown
Member

@feruzm feruzm commented Apr 11, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved robustness: the app now gracefully handles severely malformed HTML/XML inputs (mismatched tags, deep nesting, invalid character patterns) without crashing.
  • Tests

    • Added regression tests to verify document parsing behavior against multiple malformed input scenarios.
  • Chores

    • Patch release updated (changelog entry added).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d72b2d2f-95d9-403d-ad23-bac9c9e103fa

📥 Commits

Reviewing files that changed from the base of the PR and between 2984708 and fb4d606.

⛔ Files ignored due to path filters (6)
  • packages/render-helper/dist/browser/index.js is excluded by !**/dist/**
  • packages/render-helper/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/render-helper/dist/node/index.cjs is excluded by !**/dist/**
  • packages/render-helper/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/render-helper/dist/node/index.mjs is excluded by !**/dist/**
  • packages/render-helper/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (2)
  • packages/render-helper/CHANGELOG.md
  • packages/render-helper/package.json
✅ Files skipped from review due to trivial changes (2)
  • packages/render-helper/CHANGELOG.md
  • packages/render-helper/package.json

📝 Walkthrough

Walkthrough

createDoc() in the render-helper module now catches exceptions from the HTML/XML parser and returns null for pathological inputs; tests were added to assert createDoc() does not throw and returns either a Document or null for several malformed HTML cases. (49 words)

Changes

Cohort / File(s) Summary
createDoc error handling
packages/render-helper/src/helper.ts
Wraps DOMParser.parseFromString() in a try/catch; on parsing exceptions returns null instead of letting errors propagate.
Regression tests
packages/render-helper/src/helper.spec.ts
Adds expectDocumentOrNull(result) helper and three tests asserting createDoc() does not throw and returns `Document
Release metadata
packages/render-helper/CHANGELOG.md, packages/render-helper/package.json
Bumps package version to 2.4.30 and adds a changelog entry noting the DOM parser improvement tied to issue #753.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Render helper update #643: Modifies the same createDoc() implementation in packages/render-helper/src/helper.ts with preprocessing to remove duplicate attributes and parser-related tweaks.
  • Fixes and render-helper #617: Also touches createDoc() in packages/render-helper/src/helper.ts, wrapping input in a <body> before parsing to handle malformed fragments.

Suggested labels

patch

Poem

🐰 I nibbled at tags that frayed and curled,
I hopped through tangled nests of HTML,
When parsers hiccuped, I stayed serene and small,
Returning null instead of a crash for all,
A gentle hop — no panic, just a soft fall.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Dom parser improvement' is directly related to the main change: adding error handling to the createDoc() function's DOM parser to gracefully degrade on malformed HTML instead of throwing exceptions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rren

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/render-helper/src/helper.spec.ts (1)

452-462: Strengthen the last two regressions with a return-shape assertion.

These tests currently only check “no throw”; they should also assert the result is either null or a document-like object (as done in the first regression test).

Suggested assertion strengthening
 it('should return null (not throw) on deeply malformed HTML', () => {
   const input = '<div><p><span><a><b><i>no closing tags here'
   expect(() => createDoc(input)).not.toThrow()
+  const doc = createDoc(input)
+  if (doc !== null) {
+    expect(typeof doc.getElementsByTagName).toBe('function')
+  }
 })

 it('should return null (not throw) on invalid XML characters', () => {
   const input = '<div>less than < something</div>'
   expect(() => createDoc(input)).not.toThrow()
+  const doc = createDoc(input)
+  if (doc !== null) {
+    expect(typeof doc.getElementsByTagName).toBe('function')
+  }
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/render-helper/src/helper.spec.ts` around lines 452 - 462, The two
tests that only assert "not to throw" need to also verify the return shape from
createDoc: call createDoc(input) in each ("should return null (not throw) on
deeply malformed HTML" and "should return null (not throw) on invalid XML
characters") and assert the result is either null or a document-like object
(same shape check used in the earlier regression test), e.g., expect(result ===
null || /* document-like predicate */). Update the assertions to mirror the
pattern used in the first regression test to ensure the function returns null or
a parsed document object.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/render-helper/src/helper.spec.ts`:
- Around line 441-450: The test title for the spec around createDoc is
misleading: it says "should return null" but the assertion accepts either null
or a Document; update the test to make the contract consistent by either
renaming the test to "should not throw on mismatched body/p tags" (and keep the
current assertions that allow null or Document) or change the assertion to
require null explicitly; locate the test block containing
createDoc('<p>oops<p>hello') and update the it(...) description or the
expectation to match the intended guarantee.

---

Nitpick comments:
In `@packages/render-helper/src/helper.spec.ts`:
- Around line 452-462: The two tests that only assert "not to throw" need to
also verify the return shape from createDoc: call createDoc(input) in each
("should return null (not throw) on deeply malformed HTML" and "should return
null (not throw) on invalid XML characters") and assert the result is either
null or a document-like object (same shape check used in the earlier regression
test), e.g., expect(result === null || /* document-like predicate */). Update
the assertions to mirror the pattern used in the first regression test to ensure
the function returns null or a parsed document object.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 980b2438-534b-4289-b558-71a5fce6c088

📥 Commits

Reviewing files that changed from the base of the PR and between d4c3264 and c70c6e3.

📒 Files selected for processing (2)
  • packages/render-helper/src/helper.spec.ts
  • packages/render-helper/src/helper.ts

@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR label Apr 11, 2026
@feruzm feruzm merged commit 1c5fb46 into develop Apr 11, 2026
1 check passed
@feruzm feruzm deleted the rren branch April 11, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant