Repository navigation
Fix: Don't process v-html injected content as Vue template expressions - #52
Conversation
lucaswerkmeister
left a comment
There was a problem hiding this comment.
There should be some tests for this change.
a80e4ea to
401324e
Compare
lucaswerkmeister
left a comment
There was a problem hiding this comment.
(There should still be some tests for this change.)
401324e to
64884d0
Compare
|
Ok, I added two test cases for the |
lucaswerkmeister
left a comment
There was a problem hiding this comment.
LGTM, one optional suggestion. Haven’t tried it out locally yet.
64884d0 to
04b55c8
Compare
lucaswerkmeister
left a comment
There was a problem hiding this comment.
LGTM, one comment for potential follow-up but in the meantime I think this is okay to merge.
| @@ -59,7 +60,7 @@ private function handleNode( DOMNode $node, array $data ) { | |||
| $this->handleAttributeBinding( $node, $data ); | |||
| $this->handleConditionalNodes( $node->childNodes, $data ); | |||
There was a problem hiding this comment.
I wonder if this part should also be changed… what if the v-html returns markup with v-if conditions inside?
There was a problem hiding this comment.
Could you please give an example so I can also study and fix a solution as a follow-up PR?
There was a problem hiding this comment.
I don’t have an example yet, I haven’t checked this at all. I’m just wondering if there’s a bug here.
But I guess it would be something like: template <div v-html="html"></div> and [ 'html' => '<span v-if="false">content</span> ] should evaluate to <div><span v-if="false">content</span></div> and not <div></div>.
There was a problem hiding this comment.
Hi @lucaswerkmeister , coming back to this possible bug issue, in order to evaluate it, I created a simple test locally:
'v-if in v-html content is not evaluated' => [
'<div v-html="html"></div>',
[ 'html' => '<span v-if="false">content</span>' ],
'<div><span v-if="false">content</span></div>',
],
Problem
When a snak value contained text like {{P}}, the server-side renderer crashed with:
RuntimeException: Undefined variable 'P'This happened because after
handleRawHtmlinjected HTML viaappendHTML, the child traversal inhandleNodewould recurse into the newly-injected nodes and callreplaceMustacheVariableson them .. treating user content like{{P}}as a Vue template expression.HTML-entity-encoding the curly braces ({) was not a viable workaround because
HtmlParserusesDOMDocument::loadHTMLwhich decodes entities back to { before creating text nodes.Fix
In
handleNode, take a snapshot of the node's children beforehandleRawHtmlruns, then use that snapshot in theforeachtraversal instead of the node's current children.This means only the original template children are walked and processed for Vue directives. Any HTML injected by
v-htmlis appended to the DOM but never passed tohandleNode.. matching real Vue.js behaviour, wherev-htmlcontent is treated as raw HTML and is never compiled as template expressions.Bug: T418104