From 311af226bdc47d8ab1bfabb1a109ddb33da8a1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemens=20Sch=C3=B6lhorn?= Date: Sat, 9 May 2020 19:13:59 +0200 Subject: [PATCH] fix: Use correct case for XML (SVG) elements Previously XML elements which use some upper case letters would be converted to all-lowercase during string parsing. As xml is case-sensitive, this breaks the element. An example is the XML linearGradient. This was caused by the code incorrectly converting all element names to lowercase to ensure HTML tags are correctly assigned, as they use lower case internally, but the browser function tagName returns all caps for HTML tags. Fix this by only converting HTML element names to lower case. Fix: #377 --- src/browser/dom/virtual_dom_bridge.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/browser/dom/virtual_dom_bridge.rs b/src/browser/dom/virtual_dom_bridge.rs index e5df9da4c..6ab3c5fb4 100644 --- a/src/browser/dom/virtual_dom_bridge.rs +++ b/src/browser/dom/virtual_dom_bridge.rs @@ -315,11 +315,11 @@ impl From<&web_sys::Element> for El { /// and markdown strings. Includes children, recursively added. #[allow(clippy::too_many_lines)] fn from(ws_el: &web_sys::Element) -> Self { - // Result of tag_name is all caps, but tag From expects lower. - // Probably is more pure to match by xlmns attribute instead. - let mut el = match ws_el.tag_name().to_lowercase().as_ref() { - "svg" => El::empty_svg(ws_el.tag_name().to_lowercase().into()), - _ => El::empty(ws_el.tag_name().to_lowercase().into()), + let namespace = ws_el.namespace_uri().map(Namespace::from); + let mut el = match namespace { + // tag_name returns all caps for HTML, but Tag::from uses lowercase names for HTML + Some(Namespace::Html) => El::empty(ws_el.tag_name().to_lowercase().into()), + _ => El::empty(ws_el.tag_name().into()), }; // Populate attributes @@ -420,14 +420,14 @@ impl From<&web_sys::Element> for El { "solidcolor", ]; - if svg_tags.contains(&ws_el.tag_name().to_lowercase().as_str()) { + if svg_tags.contains(&ws_el.tag_name().as_str()) { el.namespace = Some(Namespace::Svg); } - if let Some(ns) = ws_el.namespace_uri() { + if let Some(ref ns) = namespace { // Prevent attaching a `xlmns` attribute to normal HTML elements. - if ns != "http://www.w3.org/1999/xhtml" { - el.namespace = Some(ns.into()); + if ns != &Namespace::Html { + el.namespace = namespace; } }