Skip to content

Commit

Permalink
fix #5591: keep ssr template interpolation whitespace-insensitive (#5597
Browse files Browse the repository at this point in the history
)
  • Loading branch information
HerringtonDarkholme authored and yyx990803 committed May 7, 2017
1 parent 5c0c8c8 commit 9ac4c41
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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()
})
})
}
})

0 comments on commit 9ac4c41

Please sign in to comment.