Allow xlink:href to get removed, fix option.value in mock
This commit is contained in:
parent
e36a8db9d4
commit
348bed0a7e
6 changed files with 30 additions and 11 deletions
|
|
@ -38,6 +38,7 @@
|
||||||
- core: Event listeners allocate less memory, swap at low cost, and are properly diffed now when rendered via `m.mount()`/`m.redraw()`.
|
- core: Event listeners allocate less memory, swap at low cost, and are properly diffed now when rendered via `m.mount()`/`m.redraw()`.
|
||||||
- core: `Object.prototype` properties can no longer interfere with event listener calls.
|
- core: `Object.prototype` properties can no longer interfere with event listener calls.
|
||||||
- API: Event handlers, when set to literally `undefined` (or any non-function), are now correctly removed.
|
- API: Event handlers, when set to literally `undefined` (or any non-function), are now correctly removed.
|
||||||
|
- core: `xlink:href` attributes are now correctly removed
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -476,7 +476,7 @@ module.exports = function($window) {
|
||||||
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value)
|
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value)
|
||||||
if ((old === value && !isFormAttribute(vnode, key)) && typeof value !== "object" || value === undefined) return
|
if ((old === value && !isFormAttribute(vnode, key)) && typeof value !== "object" || value === undefined) return
|
||||||
var element = vnode.dom
|
var element = vnode.dom
|
||||||
if (key.slice(0, 6) === "xlink:") element.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value)
|
if (key.slice(0, 6) === "xlink:") element.setAttributeNS("http://www.w3.org/1999/xlink", key, value)
|
||||||
else if (key === "style") updateStyle(element, old, value)
|
else if (key === "style") updateStyle(element, old, value)
|
||||||
else if (key in element && !isAttribute(key) && ns === undefined && !isCustomElement(vnode)) {
|
else if (key in element && !isAttribute(key) && ns === undefined && !isCustomElement(vnode)) {
|
||||||
if (key === "value") {
|
if (key === "value") {
|
||||||
|
|
|
||||||
|
|
@ -376,15 +376,15 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
o(a.dom.value).equals("1")
|
o(a.dom.value).equals("1")
|
||||||
})
|
})
|
||||||
o("null becomes the empty string", function() {
|
o("null becomes 'null'", function() {
|
||||||
var a = {tag: "option", attrs: {value: null}}
|
var a = {tag: "option", attrs: {value: null}}
|
||||||
var b = {tag: "option", attrs: {value: "test"}}
|
var b = {tag: "option", attrs: {value: "test"}}
|
||||||
var c = {tag: "option", attrs: {value: null}}
|
var c = {tag: "option", attrs: {value: null}}
|
||||||
|
|
||||||
render(root, [a]);
|
render(root, [a]);
|
||||||
|
|
||||||
o(a.dom.value).equals("")
|
o(a.dom.value).equals("null")
|
||||||
o(a.dom.getAttribute("value")).equals("")
|
o(a.dom.getAttribute("value")).equals("null")
|
||||||
|
|
||||||
render(root, [b]);
|
render(root, [b]);
|
||||||
|
|
||||||
|
|
@ -393,8 +393,8 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
render(root, [c]);
|
render(root, [c]);
|
||||||
|
|
||||||
o(c.dom.value).equals("")
|
o(c.dom.value).equals("null")
|
||||||
o(c.dom.getAttribute("value")).equals("")
|
o(c.dom.getAttribute("value")).equals("null")
|
||||||
})
|
})
|
||||||
o("'' and 0 are different values", function() {
|
o("'' and 0 are different values", function() {
|
||||||
var a = {tag: "option", attrs: {value: 0}, children:[{tag:"#", children:""}]}
|
var a = {tag: "option", attrs: {value: 0}, children:[{tag:"#", children:""}]}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ o.spec("createElement", function() {
|
||||||
o(vnode.dom.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(vnode.dom.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
o(vnode.dom.firstChild.nodeName).equals("a")
|
o(vnode.dom.firstChild.nodeName).equals("a")
|
||||||
o(vnode.dom.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(vnode.dom.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
o(vnode.dom.firstChild.attributes["href"].value).equals("javascript:;")
|
o(vnode.dom.firstChild.attributes["xlink:href"].value).equals("javascript:;")
|
||||||
o(vnode.dom.firstChild.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
o(vnode.dom.firstChild.attributes["xlink:href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||||
o(vnode.dom.childNodes[1].nodeName).equals("foreignObject")
|
o(vnode.dom.childNodes[1].nodeName).equals("foreignObject")
|
||||||
o(vnode.dom.childNodes[1].firstChild.nodeName).equals("body")
|
o(vnode.dom.childNodes[1].firstChild.nodeName).equals("body")
|
||||||
o(vnode.dom.childNodes[1].firstChild.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
o(vnode.dom.childNodes[1].firstChild.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
||||||
|
|
@ -77,6 +77,24 @@ o.spec("createElement", function() {
|
||||||
|
|
||||||
o(vnode.dom.attributes["viewBox"].value).equals("0 0 100 100")
|
o(vnode.dom.attributes["viewBox"].value).equals("0 0 100 100")
|
||||||
})
|
})
|
||||||
|
o("removes xlink:href", function() {
|
||||||
|
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [
|
||||||
|
{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}}
|
||||||
|
]}
|
||||||
|
render(root, [vnode])
|
||||||
|
|
||||||
|
o(vnode.dom.nodeName).equals("svg")
|
||||||
|
o(vnode.dom.firstChild.attributes["xlink:href"].value).equals("javascript:;")
|
||||||
|
o(vnode.dom.firstChild.attributes["xlink:href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||||
|
|
||||||
|
vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [
|
||||||
|
{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {}}
|
||||||
|
]}
|
||||||
|
render(root, [vnode])
|
||||||
|
|
||||||
|
o(vnode.dom.nodeName).equals("svg")
|
||||||
|
o(vnode.dom.firstChild.attributes["xlink:href"]).equals(undefined)
|
||||||
|
})
|
||||||
o("creates mathml", function() {
|
o("creates mathml", function() {
|
||||||
var vnode = {tag: "math", ns: "http://www.w3.org/1998/Math/MathML", children: [{tag: "mrow", ns: "http://www.w3.org/1998/Math/MathML"}]}
|
var vnode = {tag: "math", ns: "http://www.w3.org/1998/Math/MathML", children: [{tag: "mrow", ns: "http://www.w3.org/1998/Math/MathML"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,7 @@ module.exports = function(options) {
|
||||||
if (element.nodeName === "OPTION") {
|
if (element.nodeName === "OPTION") {
|
||||||
var valueSetter = spy(function(value) {
|
var valueSetter = spy(function(value) {
|
||||||
/*eslint-disable no-implicit-coercion*/
|
/*eslint-disable no-implicit-coercion*/
|
||||||
this.setAttribute("value", value === null ? "" : "" + value)
|
this.setAttribute("value", "" + value)
|
||||||
/*eslint-enable no-implicit-coercion*/
|
/*eslint-enable no-implicit-coercion*/
|
||||||
})
|
})
|
||||||
Object.defineProperty(element, "value", {
|
Object.defineProperty(element, "value", {
|
||||||
|
|
|
||||||
|
|
@ -954,11 +954,11 @@ o.spec("domMock", function() {
|
||||||
o(select.selectedIndex).equals(1)
|
o(select.selectedIndex).equals(1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o("option.value = null is converted to the empty string", function() {
|
o("option.value = null is converted to 'null'", function() {
|
||||||
var option = $document.createElement("option")
|
var option = $document.createElement("option")
|
||||||
option.value = null
|
option.value = null
|
||||||
|
|
||||||
o(option.value).equals("")
|
o(option.value).equals("null")
|
||||||
})
|
})
|
||||||
o("setting valid value works with optgroup", function() {
|
o("setting valid value works with optgroup", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue