mirror of https://github.com/sveltejs/svelte
fix: execute sole static script tag (#11095)
- take into account that template could consist of a single script tag, for which querySelectorAll('script') would yield false negatives - add test to ensure that we don't execute script tags inside `@html` tags next to static script tags fixes #11082pull/11093/head
parent
3c2f4d2d55
commit
5a1c756a4e
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: execute sole static script tag
|
@ -1,7 +1,7 @@
|
||||
import { test } from '../../test';
|
||||
import { test } from '../../assert';
|
||||
|
||||
export default test({
|
||||
test({ assert, component, window }) {
|
||||
test({ assert, window }) {
|
||||
document.dispatchEvent(new Event('DOMContentLoaded'));
|
||||
assert.equal(window.document.querySelector('button')?.textContent, 'Hello world');
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import { test } from '../../assert';
|
||||
|
||||
export default test({
|
||||
// Test that @html does not execute scripts when instantiated in the client.
|
||||
// Needs to be in this test suite because JSDOM does not quite get this right.
|
||||
mode: ['client'],
|
||||
test({ window, assert }) {
|
||||
// In here to give effects etc time to execute
|
||||
assert.htmlEqual(
|
||||
window.document.body.innerHTML,
|
||||
`<main>
|
||||
<div><script></script></div><script>document.body.innerHTML = 'this should not be executed'</script>
|
||||
<script></script><script>document.body.innerHTML = 'this neither'</script>
|
||||
</main>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
<div>
|
||||
<script></script>
|
||||
</div>
|
||||
{@html `<script>document.body.innerHTML = 'this should not be executed'</script>`}
|
||||
{#if true}
|
||||
<script></script>{@html `<script>document.body.innerHTML = 'this neither'</script>`}
|
||||
{/if}
|
@ -0,0 +1,11 @@
|
||||
import { test } from '../../assert';
|
||||
|
||||
export default test({
|
||||
// Test that template with sole script tag does execute when instantiated in the client.
|
||||
// Needs to be in this test suite because JSDOM does not quite get this right.
|
||||
mode: ['client'],
|
||||
test({ window, assert }) {
|
||||
// In here to give effects etc time to execute
|
||||
assert.htmlEqual(window.document.body.innerHTML, 'this should be executed');
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
<div></div>
|
||||
{#if true}
|
||||
<script>document.body.innerHTML = 'this should be executed'</script>
|
||||
{/if}
|
Loading…
Reference in new issue