From 05299610ea3e89ddbcfe4d8ede0c298223766423 Mon Sep 17 00:00:00 2001 From: AchillesJ Date: Sat, 6 Jan 2018 06:44:44 +0800 Subject: [PATCH] fix(vdom): svg inside foreignObject should be rendered with correct namespace (fix #7330) (#7350) * add failed test case * fix failed test case * fix(vdom): svg inside foreignObject should be rendered with correct namespace * adjust comments --- src/core/vdom/create-element.js | 3 ++- test/unit/modules/vdom/create-element.spec.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index 248bcff18f..c5cde2c642 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -139,7 +139,8 @@ function applyNS (vnode, ns, force) { if (isDef(vnode.children)) { for (let i = 0, l = vnode.children.length; i < l; i++) { const child = vnode.children[i] - if (isDef(child.tag) && (isUndef(child.ns) || isTrue(force))) { + if (isDef(child.tag) && ( + isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) { applyNS(child, ns, force) } } diff --git a/test/unit/modules/vdom/create-element.spec.js b/test/unit/modules/vdom/create-element.spec.js index f2fddcf6d1..16a5e4a8a7 100644 --- a/test/unit/modules/vdom/create-element.spec.js +++ b/test/unit/modules/vdom/create-element.spec.js @@ -135,10 +135,12 @@ describe('create-element', () => { it('render svg foreignObject with correct namespace', () => { const vm = new Vue({}) const h = vm.$createElement - const vnode = h('svg', [h('foreignObject', [h('p')])]) + const vnode = h('svg', [h('foreignObject', [h('p'), h('svg')])]) expect(vnode.ns).toBe('svg') expect(vnode.children[0].ns).toBe('svg') expect(vnode.children[0].children[0].ns).toBeUndefined() + // #7330 + expect(vnode.children[0].children[1].ns).toBe('svg') }) // #6642