mirror of https://github.com/sveltejs/svelte
[fix] Specify svg namespace if {@html} is used in svg (#7464)
* add test * create svg element if {@html} tag is inside of svg * always use claim_html_tagpull/7469/head
parent
eb37f4a285
commit
1803290864
@ -0,0 +1,35 @@
|
||||
export default {
|
||||
html: `
|
||||
<svg width="100" height="60">
|
||||
<circle cx="25" cy="30" r="24" fill="#FFD166"></circle>
|
||||
<circle cx="75" cy="30" r="24" fill="#118AB2"></circle>
|
||||
</svg>
|
||||
`,
|
||||
test({ assert, target, component }) {
|
||||
|
||||
let svg = target.querySelector('svg');
|
||||
let circles = target.querySelectorAll('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(2, circles.length);
|
||||
assert.equal(circles[0].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circles[1].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
|
||||
component.width = 200;
|
||||
component.height = 120;
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<svg width="200" height="120">
|
||||
<circle cx="50" cy="60" r="24" fill="#FFD166"></circle>
|
||||
<circle cx="150" cy="60" r="24" fill="#118AB2"></circle>
|
||||
</svg>
|
||||
`
|
||||
);
|
||||
svg = target.querySelector('svg');
|
||||
circles = target.querySelectorAll('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(2, circles.length);
|
||||
assert.equal(circles[0].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circles[1].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
}
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
export let width = 100
|
||||
export let height = 60
|
||||
$: circle = `<circle cx="${width/4}" cy="${height/2}" r="24" fill="#FFD166"/>`
|
||||
</script>
|
||||
|
||||
<svg width="{width}" height="{height}">
|
||||
{@html circle}
|
||||
<circle cx="{width/4*3}" cy="{height/2}" r="24" fill="#118AB2"/>
|
||||
</svg>
|
@ -0,0 +1,39 @@
|
||||
export default {
|
||||
html: `
|
||||
<svg width="100" height="60">
|
||||
<rect>
|
||||
<circle cx="25" cy="30" r="24" fill="#FFD166"></circle>
|
||||
<circle cx="75" cy="30" r="24" fill="#118AB2"></circle>
|
||||
</rect>
|
||||
</svg>
|
||||
`,
|
||||
test({ assert, target, component }) {
|
||||
|
||||
let svg = target.querySelector('svg');
|
||||
let circles = target.querySelectorAll('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(2, circles.length);
|
||||
assert.equal(circles[0].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circles[1].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
|
||||
component.width = 200;
|
||||
component.height = 120;
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<svg width="200" height="120">
|
||||
<rect>
|
||||
<circle cx="50" cy="60" r="24" fill="#FFD166"></circle>
|
||||
<circle cx="150" cy="60" r="24" fill="#118AB2"></circle>
|
||||
</rect>
|
||||
</svg>
|
||||
`
|
||||
);
|
||||
svg = target.querySelector('svg');
|
||||
circles = target.querySelectorAll('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(2, circles.length);
|
||||
assert.equal(circles[0].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circles[1].namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
export let width = 100
|
||||
export let height = 60
|
||||
$: circle = `<circle cx="${width/4}" cy="${height/2}" r="24" fill="#FFD166"/>`
|
||||
</script>
|
||||
|
||||
<svg width="{width}" height="{height}">
|
||||
<rect>
|
||||
{@html circle}
|
||||
<circle cx="{width/4*3}" cy="{height/2}" r="24" fill="#118AB2"/>
|
||||
</rect>
|
||||
</svg>
|
@ -0,0 +1,33 @@
|
||||
export default {
|
||||
html: `
|
||||
<svg>
|
||||
<foreignObject>
|
||||
<circle cx="25" cy="30" r="24" fill="#FFD166"></circle>
|
||||
</foreignObject>
|
||||
</svg>
|
||||
`,
|
||||
test({ assert, target, component }) {
|
||||
|
||||
let svg = target.querySelector('svg');
|
||||
let circle = target.querySelector('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circle.namespaceURI, 'http://www.w3.org/1999/xhtml');
|
||||
|
||||
component.width = 200;
|
||||
component.height = 120;
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<svg>
|
||||
<foreignObject>
|
||||
<circle cx="50" cy="60" r="24" fill="#FFD166"></circle>
|
||||
</foreignObject>
|
||||
</svg>
|
||||
`
|
||||
);
|
||||
svg = target.querySelector('svg');
|
||||
circle = target.querySelector('circle');
|
||||
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
|
||||
assert.equal(circle.namespaceURI, 'http://www.w3.org/1999/xhtml');
|
||||
}
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
export let width = 100
|
||||
export let height = 60
|
||||
$: circle = `<circle cx="${width/4}" cy="${height/2}" r="24" fill="#FFD166"/>`
|
||||
</script>
|
||||
|
||||
<svg>
|
||||
<foreignObject>
|
||||
{@html circle}
|
||||
</foreignObject>
|
||||
</svg>
|
Loading…
Reference in new issue