Skip to content

Commit

Permalink
fix(SSR): Properly handle newlines and whitespace in SSR classnames
Browse files Browse the repository at this point in the history
When encountering newlines in SSR classnames, do not render "\n"" and
instead replace the new line with a space.

Once newlines are removed, indentation from subsequent lines can leave
classnames abnormally spaced out, so replace multiple spaces with a
single space

fix vuejs#7859
  • Loading branch information
brophdawg11 committed May 4, 2018
1 parent 5e3823a commit 6b71f97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platforms/web/compiler/modules/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function transformNode (el: ASTElement, options: CompilerOptions) {
}
}
if (staticClass) {
el.staticClass = JSON.stringify(staticClass)
el.staticClass = JSON.stringify(staticClass.replace(/\n/g, ' ').replace(/ +/g, ' '))
}
const classBinding = getBindingAttr(el, 'class', false /* getStatic */)
if (classBinding) {
Expand Down
31 changes: 31 additions & 0 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,37 @@ describe('SSR: renderToString', () => {
})
})

// #7859
it('should remove and trim newlines in class attributes', done => {
renderVmWithOptions({
template: `
<div>
<div class="a b
c d">
</div>
</div>
`
}, result => {
expect(result).toContain(`<div class="a b c d"></div>`)
done()
})
})

// #7859
it('should trim excess whigtespace in class attributes', done => {
renderVmWithOptions({
template: `
<div>
<div class="a b c d">
</div>
</div>
`
}, result => {
expect(result).toContain(`<div class="a b c d"></div>`)
done()
})
})

it('should expose ssr helpers on functional context', done => {
let called = false
renderVmWithOptions({
Expand Down

0 comments on commit 6b71f97

Please sign in to comment.