A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/f036cce16377cec328bee03a3a4069275b320312 below:

Add 'nonce' option to context for ssr outlet script (#8047) · vuejs/vue@f036cce · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+29

-1

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+29

-1

lines changed Original file line number Diff line number Diff line change

@@ -198,8 +198,9 @@ export default class TemplateRenderer {

198 198

const autoRemove = process.env.NODE_ENV === 'production'

199 199

? ';(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'

200 200

: ''

201 +

const nonceAttr = context.nonce ? ` nonce="${context.nonce}"` : ''

201 202

return context[contextKey]

202 -

? `<script>window.${windowKey}=${state}${autoRemove}</script>`

203 +

? `<script${nonceAttr}>window.${windowKey}=${state}${autoRemove}</script>`

203 204

: ''

204 205

}

205 206 Original file line number Diff line number Diff line change

@@ -387,5 +387,32 @@ describe('SSR: template option', () => {

387 387

done()

388 388

})

389 389

})

390 + 391 +

it('renderToString + nonce', done => {

392 +

const interpolateTemplate = `<html><head><title>hello</title></head><body><!--vue-ssr-outlet--></body></html>`

393 +

const renderer = createRenderer({

394 +

template: interpolateTemplate

395 +

})

396 + 397 +

const context = {

398 +

state: { a: 1 },

399 +

nonce: '4AEemGb0xJptoIGFP3Nd'

400 +

}

401 + 402 +

renderer.renderToString(new Vue({

403 +

template: '<div>hi</div>'

404 +

}), context, (err, res) => {

405 +

expect(err).toBeNull()

406 +

expect(res).toContain(

407 +

`<html><head>` +

408 +

`<title>hello</title>` +

409 +

`</head><body>` +

410 +

`<div data-server-rendered="true">hi</div>` +

411 +

`<script nonce="4AEemGb0xJptoIGFP3Nd">window.__INITIAL_STATE__={"a":1}</script>` +

412 +

`</body></html>`

413 +

)

414 +

done()

415 +

})

416 +

})

390 417

}

391 418

})

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4