From b5c1bf604d7de3669ed0e6918cdf88b115a7354d Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 4 May 2016 13:17:47 -0400 Subject: [PATCH] do not merge empty class on component placeholder (fix #2789) --- src/compiler/transclude.js | 4 ++-- test/unit/specs/compiler/transclude_spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compiler/transclude.js b/src/compiler/transclude.js index 8387422b6..9b6c04c70 100644 --- a/src/compiler/transclude.js +++ b/src/compiler/transclude.js @@ -151,8 +151,8 @@ function mergeAttrs (from, to) { value = attrs[i].value if (!to.hasAttribute(name) && !specialCharRE.test(name)) { to.setAttribute(name, value) - } else if (name === 'class' && !parseText(value)) { - value.trim().split(/\s+/).forEach(function (cls) { + } else if (name === 'class' && !parseText(value) && (value = value.trim())) { + value.split(/\s+/).forEach(function (cls) { addClass(to, cls) }) } diff --git a/test/unit/specs/compiler/transclude_spec.js b/test/unit/specs/compiler/transclude_spec.js index 348e68a1a..629585285 100644 --- a/test/unit/specs/compiler/transclude_spec.js +++ b/test/unit/specs/compiler/transclude_spec.js @@ -119,6 +119,16 @@ describe('Transclude', function () { expect(res.getAttribute('title')).toBe('child') }) + // #2789 + it('empty class merge', () => { + el.setAttribute('class', '') + options.template = '
' + options.replace = true + options._asComponent = true + var res = transclude(el, options) + expect(res.getAttribute('class')).toBe('test') + }) + it('class merge for svg elements', function () { el.setAttribute('class', 'test') options.template = ''