Skip to content

Commit

Permalink
fix(ssr): handle v-text/v-html with non-string value
Browse files Browse the repository at this point in the history
fix #6572
  • Loading branch information
yyx990803 committed Sep 13, 2017
1 parent 7116af4 commit 09106f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/optimizing-compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ function elementToOpenTagSegments (el, state): Array<StringSegment> {
function childrenToSegments (el, state): Array<StringSegment> {
let binding
if ((binding = el.attrsMap['v-html'])) {
return [{ type: EXPRESSION, value: binding }]
return [{ type: EXPRESSION, value: `_s(${binding})` }]
}
if ((binding = el.attrsMap['v-text'])) {
return [{ type: INTERPOLATION, value: binding }]
return [{ type: INTERPOLATION, value: `_s(${binding})` }]
}
return el.children
? nodesToSegments(el.children, state)
Expand Down
24 changes: 24 additions & 0 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ describe('SSR: renderToString', () => {
})
})

it('v-html with null value', done => {
renderVmWithOptions({
template: '<div><div v-html="text"></div></div>',
data: {
text: null
}
}, result => {
expect(result).toContain('<div data-server-rendered="true"><div></div></div>')
done()
})
})

it('v-text', done => {
renderVmWithOptions({
template: '<div><div v-text="text"></div></div>',
Expand All @@ -386,6 +398,18 @@ describe('SSR: renderToString', () => {
})
})

it('v-text with null value', done => {
renderVmWithOptions({
template: '<div><div v-text="text"></div></div>',
data: {
text: null
}
}, result => {
expect(result).toContain('<div data-server-rendered="true"><div></div></div>')
done()
})
})

it('child component (hoc)', done => {
renderVmWithOptions({
template: '<child class="foo" :msg="msg"></child>',
Expand Down

0 comments on commit 09106f0

Please sign in to comment.