Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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()
})
})
}
})