From 4633697214387763c95f92b4d3d83bf69e08698b Mon Sep 17 00:00:00 2001 From: halfnelson Date: Sat, 1 May 2021 00:10:49 +1000 Subject: [PATCH] Don't auto change to svg namespace when in foreign namespace (#6261) --- src/compiler/compile/nodes/Element.ts | 6 ++++-- .../_config.js | 7 +++++-- .../main.svelte | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 77cb2e062d..c9529fcbcb 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..0439aca06a 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. +// Test support for the `foreign` namespace preserving attribute case, +// including ensuring that SVG 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..52b3e646e1 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 @@ -