From 6c4824762e39ac4f249fd662bda3c00cc6a818db Mon Sep 17 00:00:00 2001 From: Alex Addams Date: Thu, 30 May 2019 14:50:05 +0100 Subject: [PATCH] fix(v-pre): do not alter attributes close #10087 --- src/platforms/web/runtime/modules/attrs.js | 6 ++++-- test/unit/features/directives/pre.spec.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index b5e0640305c..245b4939fc3 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -39,7 +39,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { cur = attrs[key] old = oldAttrs[key] if (old !== cur) { - setAttr(elm, key, cur) + setAttr(elm, key, cur, vnode.data.pre) } } // #4391: in IE9, setting type can reset value for input[type=radio] @@ -59,9 +59,11 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } } -function setAttr (el: Element, key: string, value: any) { +function setAttr (el: Element, key: string, value: any, isInPre: any) { if (el.tagName.indexOf('-') > -1) { baseSetAttr(el, key, value) + } else if(isInPre) { + baseSetAttr(el, key, value) } else if (isBooleanAttr(key)) { // set attribute for blank value // e.g. diff --git a/test/unit/features/directives/pre.spec.js b/test/unit/features/directives/pre.spec.js index ed48bf0f860..a876587ac20 100644 --- a/test/unit/features/directives/pre.spec.js +++ b/test/unit/features/directives/pre.spec.js @@ -42,4 +42,15 @@ describe('Directive v-pre', function () { vm.$mount() expect(vm.$el.firstChild.tagName).toBe('VTEST') }) + + // #10087 + it('should not compile attributes', function () { + Vue.component('vtest', { template: `
Hello World
` }) + const vm = new Vue({ + template: '
', + replace: true + }) + vm.$mount() + expect(vm.$el.firstChild.getAttribute('open')).toBe('hello') + }) })