diff --git a/src/config/element.rs b/src/config/element.rs index 42bc2db..1f2b1fc 100644 --- a/src/config/element.rs +++ b/src/config/element.rs @@ -74,7 +74,12 @@ impl WidgetUse { attrs: elem .attributes() .iter() - .map(|attr| (AttrName(attr.name().to_owned()), AttrValue::parse_string(attr.value()))) + .map(|attr| { + ( + AttrName(attr.name().to_owned()), + AttrValue::parse_string(&xml_ext::resolve_escaped_symbols(&attr.value())), + ) + }) .collect::>(), ..WidgetUse::default() }, diff --git a/src/config/script_var.rs b/src/config/script_var.rs index dc2ac6b..5e9a999 100644 --- a/src/config/script_var.rs +++ b/src/config/script_var.rs @@ -54,7 +54,7 @@ impl ScriptVar { let name = VarName(xml.attr("name")?.to_owned()); let command = xml.only_child()?.as_text()?.text(); if let Ok(interval) = xml.attr("interval") { - let interval = util::parse_duration(interval)?; + let interval = util::parse_duration(&interval)?; Ok(ScriptVar::Poll(PollScriptVar { name, command, interval })) } else { Ok(ScriptVar::Tail(TailScriptVar { name, command })) diff --git a/src/config/xml_ext.rs b/src/config/xml_ext.rs index 738a0da..b8cdf9c 100644 --- a/src/config/xml_ext.rs +++ b/src/config/xml_ext.rs @@ -11,6 +11,11 @@ macro_rules! with_text_pos_context { }}; } +/// resolve symbols such as " to replace them with the actual " symbol +pub fn resolve_escaped_symbols(s: &str) -> String { + s.replace(""", "\"").replace("<", "<").replace(">", ">") +} + #[derive(Debug, Clone)] pub enum XmlNode<'a, 'b> { Element(XmlElement<'a, 'b>), @@ -58,7 +63,7 @@ fn get_text_from_text_range(s: &str, (start_pos, end_pos): (TextPos, TextPos)) - if let Some(last_line) = code_text.last_mut() { *last_line = last_line.split_at(end_pos.col as usize - 1).0; } - code_text.join("\n") + resolve_escaped_symbols(&code_text.join("\n")) } impl<'a, 'b> XmlNode<'a, 'b> { @@ -71,7 +76,7 @@ impl<'a, 'b> XmlNode<'a, 'b> { } pub fn as_text_or_sourcecode(&self) -> String { - self.as_text().map(|c| c.text()).unwrap_or_else(|_| self.get_sourcecode()) + self.as_text().map(|c| resolve_escaped_symbols(&c.text())).unwrap_or_else(|_| self.get_sourcecode()) } pub fn as_text(&self) -> Result<&XmlText<'a, 'b>> { @@ -118,7 +123,7 @@ impl<'a, 'b> fmt::Display for XmlText<'a, 'b> { impl<'a, 'b> XmlText<'a, 'b> { pub fn text(&self) -> String { - self.0.text().unwrap_or_default().trim_lines().trim_matches('\n').to_owned() + self.0.text().map(resolve_escaped_symbols).unwrap_or_default().trim_lines().trim_matches('\n').to_owned() } pub fn text_pos(&self) -> TextPos { @@ -181,10 +186,11 @@ impl<'a, 'b> XmlElement<'a, 'b> { self.0.attributes() } - pub fn attr(&self, key: &str) -> Result<&str> { + pub fn attr(&self, key: &str) -> Result { with_text_pos_context! { self => self.0 .attribute(key) + .map(resolve_escaped_symbols) .with_context(|| anyhow!("'{}' missing attribute '{}'", self.as_tag_string(), key))? } }