From 6c4605fc8a74d60495789a3918c457ea101cbb38 Mon Sep 17 00:00:00 2001 From: Dave Poulter Date: Tue, 13 Aug 2019 17:36:59 +0100 Subject: [PATCH] Fix namespace for svg elements inside slots Fixes #3321 --- src/compiler/compile/nodes/Element.ts | 2 +- .../samples/svg-slot-namespace/Widget.svelte | 3 +++ .../samples/svg-slot-namespace/_config.js | 17 +++++++++++++++++ .../samples/svg-slot-namespace/main.svelte | 9 +++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/svg-slot-namespace/Widget.svelte create mode 100644 test/runtime/samples/svg-slot-namespace/_config.js create mode 100644 test/runtime/samples/svg-slot-namespace/main.svelte diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 62bc620590..e08e1f963d 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -84,7 +84,7 @@ function get_namespace(parent: Element, element: Element, explicit_namespace: st : null); } - if (element.name.toLowerCase() === 'svg') return namespaces.svg; + if (svg.test(element.name.toLowerCase())) return namespaces.svg; if (parent_element.name.toLowerCase() === 'foreignobject') return null; return parent_element.namespace; diff --git a/test/runtime/samples/svg-slot-namespace/Widget.svelte b/test/runtime/samples/svg-slot-namespace/Widget.svelte new file mode 100644 index 0000000000..ebfe572dc7 --- /dev/null +++ b/test/runtime/samples/svg-slot-namespace/Widget.svelte @@ -0,0 +1,3 @@ + + + diff --git a/test/runtime/samples/svg-slot-namespace/_config.js b/test/runtime/samples/svg-slot-namespace/_config.js new file mode 100644 index 0000000000..b53f5b0294 --- /dev/null +++ b/test/runtime/samples/svg-slot-namespace/_config.js @@ -0,0 +1,17 @@ +export default { + html: ` +
+ + + +
+ `, + + test({ assert, target }) { + const div = target.querySelector('div'); + assert.equal(div.namespaceURI, 'http://www.w3.org/1999/xhtml'); + + const line = target.querySelector('line'); + assert.equal(line.namespaceURI, 'http://www.w3.org/2000/svg'); + } +}; diff --git a/test/runtime/samples/svg-slot-namespace/main.svelte b/test/runtime/samples/svg-slot-namespace/main.svelte new file mode 100644 index 0000000000..d6bac9f065 --- /dev/null +++ b/test/runtime/samples/svg-slot-namespace/main.svelte @@ -0,0 +1,9 @@ + + +
+ + + +