Fixes #629 - [vdom] Rendering unescaped HTML produces non-functioning HTML input controls

This commit is contained in:
Patrick Steele-Idem 2017-03-28 14:58:32 -06:00
parent 91f2dc354d
commit a94e2e738a
6 changed files with 53 additions and 2 deletions

View File

@ -74,6 +74,13 @@ function morphdom(
vCurChild = vCurChild.nextSibling;
}
if (vEl.$__nodeType === 1) {
var elHandler = specialElHandlers[vEl.nodeName];
if (elHandler !== undefined) {
elHandler(realEl, vEl);
}
}
return realEl;
}

View File

@ -61,7 +61,7 @@ module.exports = {
var i = 0;
var curChild = toEl.firstChild;
while(curChild) {
if (curChild.nodeName == 'OPTION') {
if (curChild.$__nodeName == 'OPTION') {
if (curChild.$__hasAttribute('selected')) {
selectedIndex = i;
break;

View File

@ -1,4 +1,6 @@
/* jshint newcap:false */
var specialElHandlers = require('../../morphdom/specialElHandlers');
function VNode() {}
VNode.prototype = {
@ -89,6 +91,13 @@ VNode.prototype = {
curChild = curChild.nextSibling;
}
if (this.$__nodeType === 1) {
var elHandler = specialElHandlers[this.$__nodeName];
if (elHandler !== undefined) {
elHandler(actualNode, this);
}
}
return actualNode;
}

View File

@ -44,7 +44,9 @@ function virtualize(node) {
}
var vdomEl = new VElement(tagName, attrs, null, flags);
vdomEl.$__namespaceURI = node.namespaceURI;
if (node.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
vdomEl.$__namespaceURI = node.namespaceURI;
}
if (vdomEl.$__isTextArea) {
vdomEl.$__value = node.value;

View File

@ -0,0 +1,10 @@
class {
onCreate() {
this.state = {
html: "<input type='text' name='test' value='x' />"
}
}
}
<div>$!{state.html}</div>

View File

@ -0,0 +1,23 @@
var expect = require('chai').expect;
module.exports = function(helpers) {
var component = helpers.mount(require('./index'), { });
expect(component.el.childNodes.length).to.equal(1);
expect(component.el.firstChild.nodeName).to.equal('INPUT');
expect(component.el.firstChild.value).to.equal('x');
component.state.html = '<textarea>HELLO WORLD!</textarea>';
component.update();
expect(component.el.childNodes.length).to.equal(1);
expect(component.el.firstChild.nodeName).to.equal('TEXTAREA');
expect(component.el.firstChild.value).to.equal('HELLO WORLD!');
component.state.html = '<select><option value="1">One</option><option value="2" selected>Two</option></select>';
component.update();
expect(component.el.childNodes.length).to.equal(1);
expect(component.el.firstChild.nodeName).to.equal('SELECT');
expect(component.el.firstChild.selectedIndex).to.equal(1);
};