Skip to content

Commit 9ac4c41

Browse files
HerringtonDarkholmeyyx990803
authored andcommitted
fix vuejs#5591: keep ssr template interpolation whitespace-insensitive (vuejs#5597)
1 parent 5c0c8c8 commit 9ac4c41

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/server/template-renderer/parse-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const compile = require('lodash.template')
44
const compileOptions = {
5-
escape: /{{[^{]([\s\S]+?)[^}]}}/g,
5+
escape: /{{([^{][\s\S]+?[^}])}}/g,
66
interpolate: /{{{([\s\S]+?)}}}/g
77
}
88

test/ssr/ssr-template.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,38 @@ describe('SSR: template option', () => {
330330
})
331331
})
332332
})
333+
334+
it('whitespace insensitive interpolation', done => {
335+
const interpolateTemplate = `<html><head><title>{{title}}</title></head><body><!--vue-ssr-outlet-->{{{snippet}}}</body></html>`
336+
const renderer = createRenderer({
337+
template: interpolateTemplate
338+
})
339+
340+
const context = {
341+
title: '<script>hacks</script>',
342+
snippet: '<div>foo</div>',
343+
head: '<meta name="viewport" content="width=device-width">',
344+
styles: '<style>h1 { color: red }</style>',
345+
state: { a: 1 }
346+
}
347+
348+
renderer.renderToString(new Vue({
349+
template: '<div>hi</div>'
350+
}), context, (err, res) => {
351+
expect(err).toBeNull()
352+
expect(res).toContain(
353+
`<html><head>` +
354+
// double mustache should be escaped
355+
`<title>&lt;script&gt;hacks&lt;/script&gt;</title>` +
356+
`${context.head}${context.styles}</head><body>` +
357+
`<div data-server-rendered="true">hi</div>` +
358+
`<script>window.__INITIAL_STATE__={"a":1}</script>` +
359+
// triple should be raw
360+
`<div>foo</div>` +
361+
`</body></html>`
362+
)
363+
done()
364+
})
365+
})
333366
}
334367
})

0 commit comments

Comments
 (0)