Skip to content

Commit 4633697

Browse files
authored
Don't auto change to svg namespace when in foreign namespace (#6261)
1 parent a39fc8d commit 4633697

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ function get_namespace(parent: Element, element: Element, explicit_namespace: st
107107
: null);
108108
}
109109

110-
if (svg.test(element.name.toLowerCase())) return namespaces.svg;
111-
if (parent_element.name.toLowerCase() === 'foreignobject') return null;
110+
if (parent_element.namespace !== namespaces.foreign) {
111+
if (svg.test(element.name.toLowerCase())) return namespaces.svg;
112+
if (parent_element.name.toLowerCase() === 'foreignobject') return null;
113+
}
112114

113115
return parent_element.namespace;
114116
}

test/runtime/samples/attribute-casing-foreign-namespace-compiler-option/_config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// Test support for the `foreign` namespace preserving attribute case.
1+
// Test support for the `foreign` namespace preserving attribute case,
2+
// including ensuring that SVG elements don't interfere.
23

34
export default {
45
html: `
56
<page horizontalAlignment="center">
6-
<button textWrap="true" text="button">
7+
<button textWrap="true" text="button"></button>
8+
<text wordWrap="true"></text>
79
</page>
810
`,
911
options: {
@@ -16,5 +18,6 @@ export default {
1618
const attr = sel => target.querySelector(sel).attributes[0].name;
1719
assert.equal(attr('page'), 'horizontalAlignment');
1820
assert.equal(attr('button'), 'textWrap');
21+
assert.equal(attr('text'), 'wordWrap');
1922
}
2023
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<page horizontalAlignment="center">
2-
<button textWrap="true" text="button">
3-
</page>
2+
<button textWrap="true" text="button" />
3+
<text wordWrap="true" />
4+
</page>

0 commit comments

Comments
 (0)