Skip to content

Commit

Permalink
fix(v-pre): do not alter attributes (#10088)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
xmakina and posva authored Sep 21, 2020
1 parent cd57393 commit 0664cb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/platforms/web/runtime/modules/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/unit/features/directives/pre.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div v-pre><p open="hello">A Test</p></div>'
})
vm.$mount()
expect(vm.$el.firstChild.getAttribute('open')).toBe('hello')
})
})

0 comments on commit 0664cb0

Please sign in to comment.