Skip to content

Commit 4b68876

Browse files
committed
trim classes before merging during transclusion (fix #2426)
1 parent 2731452 commit 4b68876

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/compiler/transclude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function mergeAttrs (from, to) {
152152
if (!to.hasAttribute(name) && !specialCharRE.test(name)) {
153153
to.setAttribute(name, value)
154154
} else if (name === 'class' && !parseText(value)) {
155-
value.split(/\s+/).forEach(function (cls) {
155+
value.trim().split(/\s+/).forEach(function (cls) {
156156
addClass(to, cls)
157157
})
158158
}

test/unit/specs/misc_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,20 @@ describe('Misc', function () {
473473
})
474474
expect(vm.$el.textContent).toBe('default content slot1')
475475
})
476+
477+
// #2426
478+
it('class merge untrimmed', function () {
479+
expect(function () {
480+
new Vue({
481+
el: document.createElement('div'),
482+
template: '<test class="p1 p2 "></test>',
483+
components: {
484+
test: {
485+
template: '<div class="hi"></div>',
486+
replace: true
487+
}
488+
}
489+
})
490+
}).not.toThrow()
491+
})
476492
})

0 commit comments

Comments
 (0)