From 16bcd1074a8b86ec01aeb4798a89400b389c1b1e Mon Sep 17 00:00:00 2001 From: halfnelson Date: Fri, 30 Apr 2021 07:23:42 +1000 Subject: [PATCH] don't auto svg in foreign --- src/compiler/compile/nodes/Element.ts | 6 ++++-- .../_config.js | 5 ++++- .../main.svelte | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 77cb2e062d..91aa238df1 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -107,8 +107,10 @@ function get_namespace(parent: Element, element: Element, explicit_namespace: st : null); } - if (svg.test(element.name.toLowerCase())) return namespaces.svg; - if (parent_element.name.toLowerCase() === 'foreignobject') return null; + if (parent_element.namespace != namespaces.foreign) { + 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/attribute-casing-foreign-namespace-compiler-option/_config.js b/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/_config.js index 1225c64fc2..1c78822a9d 100644 --- a/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/_config.js +++ b/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/_config.js @@ -1,9 +1,11 @@ // Test support for the `foreign` namespace preserving attribute case. +// including ensuring that svg named elements don't interfere export default { html: ` - + `, options: { @@ -16,5 +18,6 @@ export default { const attr = sel => target.querySelector(sel).attributes[0].name; assert.equal(attr('page'), 'horizontalAlignment'); assert.equal(attr('button'), 'textWrap'); + assert.equal(attr('text'), 'wordWrap'); } }; diff --git a/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/main.svelte b/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/main.svelte index 6300ab3b63..1df71c1684 100644 --- a/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/main.svelte +++ b/test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/main.svelte @@ -1,3 +1,4 @@ -