Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to quick-xml 0.37 #477

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ codepage = "0.1.1"
encoding_rs = "0.8"
log = "0.4"
serde = "1.0"
quick-xml = { version = "0.36", features = ["encoding"] }
quick-xml = { version = "0.37", features = ["encoding"] }
zip = { version = "2", default-features = false, features = ["deflate"] }
chrono = { version = "0.4", features = [
"serde",
Expand Down
11 changes: 11 additions & 0 deletions src/ods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ pub enum OdsError {
Password,
/// Worksheet not found
WorksheetNotFound(String),

/// XML attribute error
AttrError(quick_xml::events::attributes::AttrError),
/// XML encoding error
EncodingError(quick_xml::encoding::EncodingError),
}

/// Ods reader options
Expand All @@ -74,6 +79,8 @@ from_err!(zip::result::ZipError, OdsError, Zip);
from_err!(quick_xml::Error, OdsError, Xml);
from_err!(std::string::ParseError, OdsError, Parse);
from_err!(std::num::ParseFloatError, OdsError, ParseFloat);
from_err!(quick_xml::events::attributes::AttrError, OdsError, Xml);
from_err!(quick_xml::encoding::EncodingError, OdsError, Xml);

impl std::fmt::Display for OdsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand All @@ -94,6 +101,8 @@ impl std::fmt::Display for OdsError {
}
OdsError::Password => write!(f, "Workbook is password protected"),
OdsError::WorksheetNotFound(name) => write!(f, "Worksheet '{name}' not found"),
OdsError::AttrError(e) => write!(f, "XML attribute Error: {e}"),
OdsError::EncodingError(e) => write!(f, "XML encoding Error: {e}"),
}
}
}
Expand All @@ -107,6 +116,8 @@ impl std::error::Error for OdsError {
OdsError::Parse(e) => Some(e),
OdsError::ParseInt(e) => Some(e),
OdsError::ParseFloat(e) => Some(e),
OdsError::AttrError(e) => Some(e),
OdsError::EncodingError(e) => Some(e),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ macro_rules! from_err {
($from:ty, $to:tt, $var:tt) => {
impl From<$from> for $to {
fn from(e: $from) -> $to {
$to::$var(e)
$to::$var(e.into())
}
}
};
Expand Down
11 changes: 10 additions & 1 deletion src/xlsb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ pub enum XlsbError {
Password,
/// Worksheet not found
WorksheetNotFound(String),
/// XML Encoding error
Encoding(quick_xml::encoding::EncodingError),
}

from_err!(std::io::Error, XlsbError, Io);
from_err!(zip::result::ZipError, XlsbError, Zip);
from_err!(quick_xml::Error, XlsbError, Xml);
from_err!(quick_xml::encoding::EncodingError, XlsbError, Encoding);

impl std::fmt::Display for XlsbError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -114,6 +117,7 @@ impl std::fmt::Display for XlsbError {
}
XlsbError::Password => write!(f, "Workbook is password protected"),
XlsbError::WorksheetNotFound(name) => write!(f, "Worksheet '{name}' not found"),
XlsbError::Encoding(e) => write!(f, "XML encoding error: {e}"),
}
}
}
Expand Down Expand Up @@ -183,7 +187,12 @@ impl<RS: Read + Seek> Xlsb<RS> {
key: QName(b"Target"),
value: v,
} => {
target = Some(xml.decoder().decode(&v)?.into_owned());
target = Some(
xml.decoder()
.decode(&v)
.map_err(XlsbError::Encoding)?
.into_owned(),
);
}
_ => (),
}
Expand Down
14 changes: 14 additions & 0 deletions src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pub enum XlsxError {
TableNotFound(String),
/// The specified sheet is not a worksheet
NotAWorksheet(String),
/// XML Encoding error
Encoding(quick_xml::encoding::EncodingError),
/// XML attribute error
XmlAttribute(quick_xml::events::attributes::AttrError),
}

from_err!(std::io::Error, XlsxError, Io);
Expand All @@ -98,6 +102,12 @@ from_err!(quick_xml::Error, XlsxError, Xml);
from_err!(std::string::ParseError, XlsxError, Parse);
from_err!(std::num::ParseFloatError, XlsxError, ParseFloat);
from_err!(std::num::ParseIntError, XlsxError, ParseInt);
from_err!(quick_xml::encoding::EncodingError, XlsxError, Encoding);
from_err!(
quick_xml::events::attributes::AttrError,
XlsxError,
XmlAttribute
);

impl std::fmt::Display for XlsxError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -139,6 +149,8 @@ impl std::fmt::Display for XlsxError {
XlsxError::Password => write!(f, "Workbook is password protected"),
XlsxError::TableNotFound(n) => write!(f, "Table '{n}' not found"),
XlsxError::NotAWorksheet(typ) => write!(f, "Expecting a worksheet, got {typ}"),
XlsxError::Encoding(e) => write!(f, "XML encoding error: {e}"),
XlsxError::XmlAttribute(e) => write!(f, "XML attribute error: {e}"),
}
}
}
Expand All @@ -153,6 +165,8 @@ impl std::error::Error for XlsxError {
XlsxError::Parse(e) => Some(e),
XlsxError::ParseInt(e) => Some(e),
XlsxError::ParseFloat(e) => Some(e),
XlsxError::Encoding(e) => Some(e),
XlsxError::XmlAttribute(e) => Some(e),
_ => None,
}
}
Expand Down