From 0664cb01434f3d52efd076b6aafe54066a2a762a Mon Sep 17 00:00:00 2001 From: Alex Addams Date: Mon, 21 Sep 2020 16:42:08 +0100 Subject: [PATCH] fix(v-pre): do not alter attributes (#10088) * fix(v-pre): do not alter attributes close #10087 * fix(v-pre): do not alter attributes remove component and replace option from unit test * refactor: use or * perf: check boolean before index Co-authored-by: Eduardo San Martin Morote --- src/platforms/web/runtime/modules/attrs.js | 6 +++--- test/unit/features/directives/pre.spec.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index b5e06403..f6dc500a 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,8 +59,8 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } } -function setAttr (el: Element, key: string, value: any) { - if (el.tagName.indexOf('-') > -1) { +function setAttr (el: Element, key: string, value: any, isInPre: any) { + if (isInPre || el.tagName.indexOf('-') > -1) { baseSetAttr(el, key, value) } else if (isBooleanAttr(key)) { // set attribute for blank value diff --git a/test/unit/features/directives/pre.spec.js b/test/unit/features/directives/pre.spec.js index ed48bf0f..65def9cd 100644 --- a/test/unit/features/directives/pre.spec.js +++ b/test/unit/features/directives/pre.spec.js @@ -42,4 +42,13 @@ describe('Directive v-pre', function () { vm.$mount() expect(vm.$el.firstChild.tagName).toBe('VTEST') }) + + // #10087 + it('should not compile attributes', function () { + const vm = new Vue({ + template: '

A Test

' + }) + vm.$mount() + expect(vm.$el.firstChild.getAttribute('open')).toBe('hello') + }) })