mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Merge branch 'linkmauve/minidom-rs-failure'
# Conflicts: # src/tests.rs
This commit is contained in:
commit
8924d2d594
6 changed files with 84 additions and 41 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
Version 0.8.0, released 2018-02-18:
|
||||||
|
* Additions
|
||||||
|
- Link Mauve replaced error\_chain with failure ( https://gitlab.com/lumi/minidom-rs/merge_requests/27 )
|
||||||
Version 0.6.2, released 2017-08-27:
|
Version 0.6.2, released 2017-08-27:
|
||||||
* Additions
|
* Additions
|
||||||
- Link Mauve added an implementation of IntoElements for all Into<Element> ( https://gitlab.com/lumi/minidom-rs/merge_requests/19 )
|
- Link Mauve added an implementation of IntoElements for all Into<Element> ( https://gitlab.com/lumi/minidom-rs/merge_requests/19 )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "minidom"
|
name = "minidom"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
authors = [
|
authors = [
|
||||||
"lumi <lumi@pew.im>",
|
"lumi <lumi@pew.im>",
|
||||||
"Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>",
|
"Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>",
|
||||||
|
@ -20,5 +20,6 @@ license = "MIT"
|
||||||
gitlab = { repository = "lumi/minidom-rs" }
|
gitlab = { repository = "lumi/minidom-rs" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quick-xml = "0.10.0"
|
quick-xml = "0.11.0"
|
||||||
error-chain = "0.11.0"
|
failure = "0.1.1"
|
||||||
|
failure_derive = "0.1.1"
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::str;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use error::{Error, ErrorKind, Result};
|
use error::{Error, Result};
|
||||||
|
|
||||||
use quick_xml::reader::Reader as EventReader;
|
use quick_xml::reader::Reader as EventReader;
|
||||||
use quick_xml::writer::Writer as EventWriter;
|
use quick_xml::writer::Writer as EventWriter;
|
||||||
|
@ -351,7 +351,7 @@ impl Element {
|
||||||
break build_element(reader, e)?;
|
break build_element(reader, e)?;
|
||||||
},
|
},
|
||||||
Event::Eof => {
|
Event::Eof => {
|
||||||
bail!(ErrorKind::EndOfDocument);
|
return Err(Error::EndOfDocument);
|
||||||
},
|
},
|
||||||
Event::Text { .. } |
|
Event::Text { .. } |
|
||||||
Event::End { .. } |
|
Event::End { .. } |
|
||||||
|
@ -391,23 +391,23 @@ impl Element {
|
||||||
match elem.prefix() {
|
match elem.prefix() {
|
||||||
Some(prefix) => {
|
Some(prefix) => {
|
||||||
if possible_prefix != prefix.as_bytes() {
|
if possible_prefix != prefix.as_bytes() {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
return Err(Error::InvalidElementClosed);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
return Err(Error::InvalidElementClosed);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if name != elem.name().as_bytes() {
|
if name != elem.name().as_bytes() {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
return Err(Error::InvalidElementClosed);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
if elem.prefix().is_some() {
|
if elem.prefix().is_some() {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
return Err(Error::InvalidElementClosed);
|
||||||
}
|
}
|
||||||
if possible_prefix != elem.name().as_bytes() {
|
if possible_prefix != elem.name().as_bytes() {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
return Err(Error::InvalidElementClosed);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -736,7 +736,7 @@ fn split_element_name<S: AsRef<str>>(s: S) -> Result<(Option<String>, String)> {
|
||||||
match name_parts.len() {
|
match name_parts.len() {
|
||||||
2 => Ok((Some(name_parts[0].to_owned()), name_parts[1].to_owned())),
|
2 => Ok((Some(name_parts[0].to_owned()), name_parts[1].to_owned())),
|
||||||
1 => Ok((None, name_parts[0].to_owned())),
|
1 => Ok((None, name_parts[0].to_owned())),
|
||||||
_ => bail!(ErrorKind::InvalidElement),
|
_ => Err(Error::InvalidElement),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
65
src/error.rs
65
src/error.rs
|
@ -2,34 +2,51 @@
|
||||||
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
error_chain! {
|
/// Our main error type.
|
||||||
foreign_links {
|
#[derive(Debug, Fail)]
|
||||||
XmlError(::quick_xml::errors::Error)
|
pub enum Error {
|
||||||
/// An error from quick_xml.
|
/// An error from quick_xml.
|
||||||
;
|
#[fail(display = "XML error: {}", _0)]
|
||||||
Utf8Error(::std::str::Utf8Error)
|
XmlError(#[cause] ::quick_xml::errors::Error),
|
||||||
/// An UTF-8 conversion error.
|
|
||||||
;
|
/// An UTF-8 conversion error.
|
||||||
IoError(::std::io::Error)
|
#[fail(display = "UTF-8 error: {}", _0)]
|
||||||
/// An I/O error, from std::io.
|
Utf8Error(#[cause] ::std::str::Utf8Error),
|
||||||
;
|
|
||||||
}
|
/// An I/O error, from std::io.
|
||||||
|
#[fail(display = "IO error: {}", _0)]
|
||||||
|
IoError(#[cause] ::std::io::Error),
|
||||||
|
|
||||||
errors {
|
|
||||||
/// An error which is returned when the end of the document was reached prematurely.
|
/// An error which is returned when the end of the document was reached prematurely.
|
||||||
EndOfDocument {
|
#[fail(display = "the end of the document has been reached prematurely")]
|
||||||
description("the end of the document has been reached prematurely")
|
EndOfDocument,
|
||||||
display("the end of the document has been reached prematurely")
|
|
||||||
}
|
|
||||||
/// An error which is returned when an element is closed when it shouldn't be
|
/// An error which is returned when an element is closed when it shouldn't be
|
||||||
InvalidElementClosed {
|
#[fail(display = "the XML is invalid, an element was wrongly closed")]
|
||||||
description("The XML is invalid, an element was wrongly closed")
|
InvalidElementClosed,
|
||||||
display("the XML is invalid, an element was wrongly closed")
|
|
||||||
}
|
|
||||||
/// An error which is returned when an elemet's name contains more than one colon
|
/// An error which is returned when an elemet's name contains more than one colon
|
||||||
InvalidElement {
|
#[fail(display = "the XML element is invalid")]
|
||||||
description("The XML element is invalid")
|
InvalidElement,
|
||||||
display("the XML element is invalid")
|
}
|
||||||
}
|
|
||||||
|
impl From<::quick_xml::errors::Error> for Error {
|
||||||
|
fn from(err: ::quick_xml::errors::Error) -> Error {
|
||||||
|
Error::XmlError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<::std::str::Utf8Error> for Error {
|
||||||
|
fn from(err: ::std::str::Utf8Error) -> Error {
|
||||||
|
Error::Utf8Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<::std::io::Error> for Error {
|
||||||
|
fn from(err: ::std::io::Error) -> Error {
|
||||||
|
Error::IoError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Our simplified Result type.
|
||||||
|
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||||
|
|
|
@ -65,7 +65,8 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate quick_xml;
|
extern crate quick_xml;
|
||||||
#[macro_use] extern crate error_chain;
|
extern crate failure;
|
||||||
|
#[macro_use] extern crate failure_derive;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
|
@ -74,6 +75,6 @@ mod namespace_set;
|
||||||
|
|
||||||
#[cfg(test)] mod tests;
|
#[cfg(test)] mod tests;
|
||||||
|
|
||||||
pub use error::{Error, ErrorKind, Result, ResultExt};
|
pub use error::{Error, Result};
|
||||||
pub use element::{Element, Node, Children, ChildrenMut, ElementBuilder};
|
pub use element::{Element, Node, Children, ChildrenMut, ElementBuilder};
|
||||||
pub use convert::{IntoElements, IntoAttributeValue, ElementEmitter};
|
pub use convert::{IntoElements, IntoAttributeValue, ElementEmitter};
|
||||||
|
|
21
src/tests.rs
21
src/tests.rs
|
@ -226,3 +226,24 @@ fn write_comments() {
|
||||||
}
|
}
|
||||||
assert_eq!(String::from_utf8(writer).unwrap(), COMMENT_TEST_STRING);
|
assert_eq!(String::from_utf8(writer).unwrap(), COMMENT_TEST_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn xml_error() {
|
||||||
|
match "<a></b>".parse::<Element>() {
|
||||||
|
Err(::error::Error::XmlError(_)) => (),
|
||||||
|
err => panic!("No or wrong error: {:?}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
match "<a></".parse::<Element>() {
|
||||||
|
Err(::error::Error::XmlError(_)) => (),
|
||||||
|
err => panic!("No or wrong error: {:?}", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invalid_element_error() {
|
||||||
|
match "<a:b:c>".parse::<Element>() {
|
||||||
|
Err(::error::Error::InvalidElement) => (),
|
||||||
|
err => panic!("No or wrong error: {:?}", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue