Skip to content

Commit

Permalink
Upgrades quick-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Aug 24, 2024
1 parent c2e0ee7 commit cc73a42
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"testsuite",
"xml"
]
resolver = "2"

[patch.crates-io]
rio_api = { path = "api" }
Expand Down
2 changes: 1 addition & 1 deletion testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ oxiri = "0.2"
permutohedron = "0.2"

[dev-dependencies]
criterion = "0.4"
criterion = "0.5"

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions testsuite/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub struct Test {
impl fmt::Display for Test {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.kind)?;
for name in &self.name {
if let Some(name) = &self.name {
write!(f, " named \"{}\"", name)?;
}
for comment in &self.comment {
if let Some(comment) = &self.comment {
write!(f, " with comment \"{}\"", comment)?;
}
write!(f, " on file \"{}\"", self.action)?;
Expand Down
1 change: 0 additions & 1 deletion turtle/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use oxiri::Iri;
use rio_api::model::*;
use std::char;
use std::io::BufRead;
use std::u8;

pub const MAX_ASCII: u8 = 0x7F;

Expand Down
1 change: 0 additions & 1 deletion turtle/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rio_api::parser::LineBytePosition;
use std::collections::VecDeque;
use std::io::{BufRead, ErrorKind, Read};
use std::str;
use std::u8;

/// Reads the file in streaming
pub struct LookAheadByteReader<R: Read> {
Expand Down
2 changes: 1 addition & 1 deletion xml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ default = []
oxilangtag = "0.1"
oxiri = "0.2"
rio_api = { version = "0.8", path="../api" }
quick-xml = "0.28"
quick-xml = "0.36"
3 changes: 0 additions & 3 deletions xml/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ impl From<RdfXmlError> for io::Error {
match error.kind {
RdfXmlErrorKind::Xml(error) => match error {
quick_xml::Error::Io(error) => io::Error::new(error.kind(), error),
quick_xml::Error::UnexpectedEof(error) => {
io::Error::new(io::ErrorKind::UnexpectedEof, error)
}
error => io::Error::new(io::ErrorKind::InvalidData, error),
},
RdfXmlErrorKind::Other(error) => io::Error::new(io::ErrorKind::InvalidData, error),
Expand Down
24 changes: 12 additions & 12 deletions xml/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use quick_xml::events::*;
use quick_xml::{NsReader, Writer};
use rio_api::model::*;
use rio_api::parser::TriplesParser;
use std::convert::TryInto;
use std::io::BufRead;
use std::str;

use crate::error::{RdfXmlError, RdfXmlErrorKind};
use crate::model::*;
use crate::utils::*;
use oxilangtag::LanguageTag;
use oxiri::Iri;
use quick_xml::escape::resolve_xml_entity;
use quick_xml::escape::unescape_with;
use quick_xml::events::attributes::Attribute;
use quick_xml::events::*;
use quick_xml::name::{LocalName, QName, ResolveResult};
use quick_xml::{NsReader, Writer};
use rio_api::model::*;
use rio_api::parser::TriplesParser;
use std::collections::{HashMap, HashSet};
use std::convert::TryInto;
use std::io::BufRead;
use std::str;

/// A [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/) streaming parser.
///
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<R: BufRead> RdfXmlParser<R> {
/// Builds the parser from a `BufRead` implementation, and a base IRI for relative IRI resolution.
pub fn new(reader: R, base_iri: Option<Iri<String>>) -> Self {
let mut reader = NsReader::from_reader(reader);
reader.expand_empty_elements(true);
reader.config_mut().expand_empty_elements = true;
Self {
reader: RdfXmlReader {
reader,
Expand All @@ -80,7 +80,7 @@ impl<R: BufRead> RdfXmlParser<R> {

/// The current byte position in the input data.
pub fn buffer_position(&self) -> usize {
self.reader.reader.buffer_position()
self.reader.reader.buffer_position().try_into().unwrap()
}
}

Expand Down Expand Up @@ -1021,7 +1021,7 @@ impl<R: BufRead> RdfXmlReader<R> {

fn convert_attribute(&self, attribute: Attribute) -> Result<String, RdfXmlError> {
Ok(attribute
.decode_and_unescape_value_with(&self.reader, |e| self.resolve_entity(e))?
.decode_and_unescape_value_with(self.reader.decoder(), |e| self.resolve_entity(e))?
.to_string())
}

Expand All @@ -1036,7 +1036,7 @@ impl<R: BufRead> RdfXmlReader<R> {
}

fn resolve_entity(&self, e: &str) -> Option<&str> {
self.custom_entities.get(e).map(|e| e.as_str())
resolve_xml_entity(e).or_else(|| self.custom_entities.get(e).map(String::as_str))
}
}

Expand Down

0 comments on commit cc73a42

Please sign in to comment.