From 6c4824762e39ac4f249fd662bda3c00cc6a818db Mon Sep 17 00:00:00 2001 From: Alex Addams Date: Thu, 30 May 2019 14:50:05 +0100 Subject: [PATCH 1/4] 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') + }) }) From 317888bcef09fff8d46ded931e1fc03a0337dc29 Mon Sep 17 00:00:00 2001 From: Alex Addams Date: Thu, 25 Jul 2019 14:27:47 +0100 Subject: [PATCH 2/4] fix(v-pre): do not alter attributes remove component and replace option from unit test --- test/unit/features/directives/pre.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit/features/directives/pre.spec.js b/test/unit/features/directives/pre.spec.js index a876587ac20..65def9cddb0 100644 --- a/test/unit/features/directives/pre.spec.js +++ b/test/unit/features/directives/pre.spec.js @@ -45,10 +45,8 @@ describe('Directive v-pre', function () { // #10087 it('should not compile attributes', function () { - Vue.component('vtest', { template: `
Hello World
` }) const vm = new Vue({ - template: '
', - replace: true + template: '

A Test

' }) vm.$mount() expect(vm.$el.firstChild.getAttribute('open')).toBe('hello') From 58d95e02e93a4ca58f5b23e366dc7a4f541034a5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 21 Sep 2020 17:08:10 +0200 Subject: [PATCH 3/4] refactor: use or --- src/platforms/web/runtime/modules/attrs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index 245b4939fc3..745a77a4cbc 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -60,9 +60,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } function setAttr (el: Element, key: string, value: any, isInPre: any) { - if (el.tagName.indexOf('-') > -1) { - baseSetAttr(el, key, value) - } else if(isInPre) { + if (el.tagName.indexOf('-') > -1 || isInPre) { baseSetAttr(el, key, value) } else if (isBooleanAttr(key)) { // set attribute for blank value From bde2d0f392b3b6d17de9699b71456b1da92b1878 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 21 Sep 2020 17:30:42 +0200 Subject: [PATCH 4/4] perf: check boolean before index --- src/platforms/web/runtime/modules/attrs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/web/runtime/modules/attrs.js b/src/platforms/web/runtime/modules/attrs.js index 745a77a4cbc..f6dc500a404 100644 --- a/src/platforms/web/runtime/modules/attrs.js +++ b/src/platforms/web/runtime/modules/attrs.js @@ -60,7 +60,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { } function setAttr (el: Element, key: string, value: any, isInPre: any) { - if (el.tagName.indexOf('-') > -1 || isInPre) { + if (isInPre || el.tagName.indexOf('-') > -1) { baseSetAttr(el, key, value) } else if (isBooleanAttr(key)) { // set attribute for blank value