mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 04:42:15 +00:00
xml: Support CDATA
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
@@ -6,6 +8,8 @@ pub enum XmlError {
|
||||
QuickXmlError(#[from] quick_xml::Error),
|
||||
#[error(transparent)]
|
||||
QuickXmlAttrError(#[from] quick_xml::events::attributes::AttrError),
|
||||
#[error(transparent)]
|
||||
FromUtf8Error(#[from] FromUtf8Error),
|
||||
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
|
||||
InvalidTag(String, String, String, String),
|
||||
#[error("Missing field {0}")]
|
||||
|
||||
@@ -81,6 +81,14 @@ impl<T: ValueDeserialize> XmlDeserialize for T {
|
||||
}
|
||||
string = String::from_utf8_lossy(text.as_ref()).to_string();
|
||||
}
|
||||
Event::CData(cdata) => {
|
||||
let text = String::from_utf8(cdata.to_vec())?;
|
||||
if !string.is_empty() {
|
||||
// Content already written
|
||||
return Err(XmlError::UnsupportedEvent("content already written"));
|
||||
}
|
||||
string = text;
|
||||
}
|
||||
Event::End(_) => break,
|
||||
Event::Eof => return Err(XmlError::Eof),
|
||||
_ => return Err(XmlError::UnsupportedEvent("todo")),
|
||||
|
||||
Reference in New Issue
Block a user