Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v-pre): do not alter attributes (fix #10087) #10088

Merged
merged 4 commits into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/platforms/web/runtime/modules/attrs.js
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 (el.tagName.indexOf('-') > -1 || isInPre) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't checking isInPre first be more optimal?

posva marked this conversation as resolved.
Show resolved Hide resolved
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
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')
})
})