From 09106f066a1ba71431e4f9f26246aaf619153e2e Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 12 Sep 2017 23:23:24 -0400 Subject: [PATCH] fix(ssr): handle v-text/v-html with non-string value fix #6572 --- src/server/optimizing-compiler/codegen.js | 4 ++-- test/ssr/ssr-string.spec.js | 24 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/server/optimizing-compiler/codegen.js b/src/server/optimizing-compiler/codegen.js index f494f8fad0..dfc4477d91 100644 --- a/src/server/optimizing-compiler/codegen.js +++ b/src/server/optimizing-compiler/codegen.js @@ -200,10 +200,10 @@ function elementToOpenTagSegments (el, state): Array { function childrenToSegments (el, state): Array { 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) diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index 784b39a4bf..3f0cc92f6a 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -374,6 +374,18 @@ describe('SSR: renderToString', () => { }) }) + it('v-html with null value', done => { + renderVmWithOptions({ + template: '
', + data: { + text: null + } + }, result => { + expect(result).toContain('
') + done() + }) + }) + it('v-text', done => { renderVmWithOptions({ template: '
', @@ -386,6 +398,18 @@ describe('SSR: renderToString', () => { }) }) + it('v-text with null value', done => { + renderVmWithOptions({ + template: '
', + data: { + text: null + } + }, result => { + expect(result).toContain('
') + done() + }) + }) + it('child component (hoc)', done => { renderVmWithOptions({ template: '',