Skip to content

Commit

Permalink
fix(v-pre): do not alter attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
xmakina committed May 30, 2019
1 parent ff911c9 commit 6c48247
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 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,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. <option disabled>Select one</option>
Expand Down
11 changes: 11 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,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: ` <div>Hello World</div>` })
const vm = new Vue({
template: '<div v-pre><vtest open="hello"></vtest></div>',
replace: true
})
vm.$mount()
expect(vm.$el.firstChild.getAttribute('open')).toBe('hello')
})
})

0 comments on commit 6c48247

Please sign in to comment.