fix(compiler-core): avoid crash on CDATA at the document root#14916
Conversation
oncdata read stack[0].ns unconditionally, but when a CDATA section appears with no open element on the stack (for example at the document root), stack[0] is undefined and parsing threw "Cannot read properties of undefined (reading 'ns')". Fall back to the root namespace (currentOptions.ns) when the stack is empty, mirroring onprocessinginstruction, so a top-level CDATA section reports CDATA_IN_HTML_CONTENT instead of crashing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughFixes a null-access in the compiler's CDATA handler by resolving namespace from the top of the element stack or falling back to options; adds a test asserting a root-level ChangesCDATA root-level handling
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
What kind of change does this PR introduce?
Bug fix.
Description
A CDATA section with no open element on the stack — e.g. at the document root — crashes the parser:
oncdatareadsstack[0].nsunconditionally, butstack[0]isundefinedwhen there's no enclosing element. The same handler works inside an element (<div><![CDATA[x]]></div>), so this only affects top-level CDATA.This falls back to the root namespace (
currentOptions.ns) when the stack is empty — mirroring the existingonprocessinginstructionhandler right below it — so top-level CDATA now reportsCDATA_IN_HTML_CONTENTinstead of throwing. Behavior inside elements and in SVG/foreign content is unchanged. Added a parser error-test case for the root position.Summary by CodeRabbit
Bug Fixes
Tests