Browse Source

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 <posva@users.noreply.github.com>
dev
Alex Addams 4 years ago
committed by GitHub
parent
commit
0664cb0143
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/platforms/web/runtime/modules/attrs.js
  2. 9
      test/unit/features/directives/pre.spec.js

6
src/platforms/web/runtime/modules/attrs.js

@ -39,7 +39,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
cur = attrs[key] cur = attrs[key]
old = oldAttrs[key] old = oldAttrs[key]
if (old !== cur) { 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] // #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) { function setAttr (el: Element, key: string, value: any, isInPre: any) {
if (el.tagName.indexOf('-') > -1) { if (isInPre || el.tagName.indexOf('-') > -1) {
baseSetAttr(el, key, value) baseSetAttr(el, key, value)
} else if (isBooleanAttr(key)) { } else if (isBooleanAttr(key)) {
// set attribute for blank value // set attribute for blank value

9
test/unit/features/directives/pre.spec.js

@ -42,4 +42,13 @@ describe('Directive v-pre', function () {
vm.$mount() vm.$mount()
expect(vm.$el.firstChild.tagName).toBe('VTEST') expect(vm.$el.firstChild.tagName).toBe('VTEST')
}) })
// #10087
it('should not compile attributes', function () {
const vm = new Vue({
template: '<div v-pre><p open="hello">A Test</p></div>'
})
vm.$mount()
expect(vm.$el.firstChild.getAttribute('open')).toBe('hello')
})
}) })

Loading…
Cancel
Save