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 #5591: keep ssr template interpolation whitespace-insensitive #5597

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/server/template-renderer/parse-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const compile = require('lodash.template')
const compileOptions = {
escape: /{{[^{]([\s\S]+?)[^}]}}/g,
escape: /{{([^{][\s\S]+?[^}])}}/g,
interpolate: /{{{([\s\S]+?)}}}/g
}

Expand Down
33 changes: 33 additions & 0 deletions test/ssr/ssr-template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,38 @@ describe('SSR: template option', () => {
})
})
})

it('whitespace insensitive interpolation', done => {
const interpolateTemplate = `<html><head><title>{{title}}</title></head><body><!--vue-ssr-outlet-->{{{snippet}}}</body></html>`
const renderer = createRenderer({
template: interpolateTemplate
})

const context = {
title: '<script>hacks</script>',
snippet: '<div>foo</div>',
head: '<meta name="viewport" content="width=device-width">',
styles: '<style>h1 { color: red }</style>',
state: { a: 1 }
}

renderer.renderToString(new Vue({
template: '<div>hi</div>'
}), context, (err, res) => {
expect(err).toBeNull()
expect(res).toContain(
`<html><head>` +
// double mustache should be escaped
`<title>&lt;script&gt;hacks&lt;/script&gt;</title>` +
`${context.head}${context.styles}</head><body>` +
`<div data-server-rendered="true">hi</div>` +
`<script>window.__INITIAL_STATE__={"a":1}</script>` +
// triple should be raw
`<div>foo</div>` +
`</body></html>`
)
done()
})
})
}
})