Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vdom): avoid executing root level script tags #11487

Merged
merged 1 commit into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})