Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ default = ["zlib-ng-compat", "mgf", "mzml"]
checksum = ["dep:md5", "dep:sha1", "dep:base16ct"]

mgf = []
mzml = ["dep:quick-xml", "checksum", "dep:memchr"]
mzml = ["dep:quick-xml", "checksum", "dep:memchr", "dep:encoding_rs"]
imzml = ["mzml", "dep:uuid"]

# mzsignal's main functionality requires a linear algebra backend.
Expand Down Expand Up @@ -201,6 +201,7 @@ pin-project-lite = { version = "0.2.16", optional = true }
memchr = { version = "2.7.4", optional = true }
libloading = { version = "0.8.6", optional = true }
zstd = { version = "0.13.3", optional = true }
encoding_rs = { version = "0.8.35", optional = true }


[dev-dependencies]
Expand Down
14 changes: 11 additions & 3 deletions src/io/mzml/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ impl<C: CentroidLike + BuildFromArrayMap, D: DeconvolutedCentroidLike + BuildFro
match attr_parsed {
Ok(attr) => match attr.key.as_ref() {
b"id" => {
self.entry_id = match attr.unescape_value() {
self.entry_id = match attr.unescape_value()
.map(|v| v.to_string())
.or_else(|_| -> Result<String, quick_xml::Error> {
log::warn!("Detected non-UTF8 character in spectrum id");
Ok(quick_xml::escape::escape(encoding_rs::mem::decode_latin1(&attr.value).as_ref()).into())
}) {
Ok(value) => value.to_string(),
Err(e) => {
return Err(xml_error!(
Expand Down Expand Up @@ -898,8 +903,11 @@ impl<C: CentroidLike + BuildFromArrayMap, D: DeconvolutedCentroidLike + BuildFro
b"id" => {
self.entry_id = attr
.unescape_value()
.expect("Error decoding id")
.to_string();
.map(|v| v.to_string())
.or_else(|_| -> Result<String, quick_xml::Error> {
log::warn!("Detected non-UTF8 character in chromatogram id");
Ok(quick_xml::escape::escape(encoding_rs::mem::decode_latin1(&attr.value).as_ref()).into())
}).unwrap();
trace!("Stored chromatogram id = {}", self.entry_id);
}
b"index" => {
Expand Down
10 changes: 8 additions & 2 deletions src/io/mzml/reading_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,14 @@ impl IndexedMzMLIndexExtractor {
if attr.key.as_ref() == b"idRef" {
self.last_id = attr
.unescape_value()
.expect("Error decoding idRef")
.to_string();
.map(|v| v.to_string())
.or_else(|_| -> Result<String, quick_xml::Error> {
log::warn!("Detected non-UTF8 character in idRef");
Ok(quick_xml::escape::escape(encoding_rs::mem::decode_latin1(&attr.value).as_ref()).into())
})
.unwrap_or_else(|e| {
panic!("Error decoding idRef on offset {e} from bytes {:?}", attr.value)
});
}
}
Err(err) => {
Expand Down
Loading