File tree 2 files changed +43
-3
lines changed
2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 6
6
resolveComponent ,
7
7
ComponentOptions ,
8
8
ref ,
9
- defineComponent
9
+ defineComponent ,
10
+ createTextVNode ,
11
+ createStaticVNode
10
12
} from 'vue'
11
13
import { escapeHtml , mockWarn } from '@vue/shared'
12
14
import { renderToString , renderComponent } from '../src/renderToString'
@@ -511,6 +513,33 @@ describe('ssr: renderToString', () => {
511
513
} )
512
514
} )
513
515
516
+ describe ( 'raw vnode types' , ( ) => {
517
+ test ( 'Text' , async ( ) => {
518
+ expect ( await renderToString ( createTextVNode ( 'hello <div>' ) ) ) . toBe (
519
+ `hello <div>`
520
+ )
521
+ } )
522
+
523
+ test ( 'Comment' , async ( ) => {
524
+ // https://www.w3.org/TR/html52/syntax.html#comments
525
+ expect (
526
+ await renderToString (
527
+ h ( 'div' , [
528
+ createCommentVNode ( '>foo' ) ,
529
+ createCommentVNode ( '->foo' ) ,
530
+ createCommentVNode ( '<!--foo-->' ) ,
531
+ createCommentVNode ( '--!>foo<!-' )
532
+ ] )
533
+ )
534
+ ) . toBe ( `<div><!--foo--><!--foo--><!--foo--><!--foo--></div>` )
535
+ } )
536
+
537
+ test ( 'Static' , async ( ) => {
538
+ const content = `<div id="ok">hello<span>world</span></div>`
539
+ expect ( await renderToString ( createStaticVNode ( content ) ) ) . toBe ( content )
540
+ } )
541
+ } )
542
+
514
543
describe ( 'scopeId' , ( ) => {
515
544
// note: here we are only testing scopeId handling for vdom serialization.
516
545
// compiled srr render functions will include scopeId directly in strings.
Original file line number Diff line number Diff line change 7
7
createVNode ,
8
8
Text ,
9
9
Comment ,
10
+ Static ,
10
11
Fragment ,
11
12
ssrUtils ,
12
13
Slots ,
@@ -229,6 +230,9 @@ function ssrCompile(
229
230
return ( compileCache [ template ] = Function ( 'require' , code ) ( require ) )
230
231
}
231
232
233
+ // https://www.w3.org/TR/html52/syntax.html#comments
234
+ const commentStripRE = / ^ - ? > | < ! - - | - - > | - - ! > | < ! - $ / g
235
+
232
236
function renderVNode (
233
237
push : PushFn ,
234
238
vnode : VNode ,
@@ -237,10 +241,17 @@ function renderVNode(
237
241
const { type, shapeFlag, children } = vnode
238
242
switch ( type ) {
239
243
case Text :
240
- push ( children as string )
244
+ push ( escapeHtml ( children as string ) )
241
245
break
242
246
case Comment :
243
- push ( children ? `<!--${ children } -->` : `<!---->` )
247
+ push (
248
+ children
249
+ ? `<!--${ ( children as string ) . replace ( commentStripRE , '' ) } -->`
250
+ : `<!---->`
251
+ )
252
+ break
253
+ case Static :
254
+ push ( children as string )
244
255
break
245
256
case Fragment :
246
257
push ( `<!--[-->` ) // open
You can’t perform that action at this time.
0 commit comments