Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(vdom): avoid executing root level script tags (#11487)
fix #11483
  • Loading branch information
shadowings-zy committed Mar 30, 2021
1 parent fa1f81e commit fb16d7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/codegen/index.js
Expand Up @@ -45,7 +45,8 @@ export function generate (
options: CompilerOptions
): CodegenResult {
const state = new CodegenState(options)
const code = ast ? genElement(ast, state) : '_c("div")'
// fix #11483, Root level <script> tags should not be rendered.
const code = ast ? (ast.tag === 'script' ? 'null' : genElement(ast, state)) : '_c("div")'
return {
render: `with(this){return ${code}}`,
staticRenderFns: state.staticRenderFns
Expand Down
13 changes: 13 additions & 0 deletions test/unit/features/component/component.spec.js
Expand Up @@ -426,4 +426,17 @@ describe('Component', () => {
vm.$destroy()
}).then(done)
})

it('render vnode with <script> tag as root element', () => {
const vm = new Vue({
template: '<scriptTest></scriptTest>',
components: {
scriptTest: {
template: '<script>console.log(1)</script>'
}
}
}).$mount()
expect(vm.$el.nodeName).toBe('#comment')
expect('Templates should only be responsible for mapping the state').toHaveBeenWarned()
})
})

0 comments on commit fb16d7b

Please sign in to comment.