mirror of
https://github.com/instant-labs/instant-xml.git
synced 2025-02-16 15:02:02 +00:00
Better errors for unknown prefixes
This commit is contained in:
parent
48450b3700
commit
8233884207
@ -134,7 +134,9 @@ impl<'xml> Context<'xml> {
|
|||||||
pub(crate) fn element_id(&self, element: &Element<'xml>) -> Result<Id<'xml>, Error> {
|
pub(crate) fn element_id(&self, element: &Element<'xml>) -> Result<Id<'xml>, Error> {
|
||||||
Ok(Id {
|
Ok(Id {
|
||||||
ns: match (element.default_ns, element.prefix) {
|
ns: match (element.default_ns, element.prefix) {
|
||||||
(_, Some(prefix)) => self.lookup(prefix).ok_or(Error::WrongNamespace)?,
|
(_, Some(prefix)) => self
|
||||||
|
.lookup(prefix)
|
||||||
|
.ok_or_else(|| Error::UnknownPrefix(prefix.to_owned()))?,
|
||||||
(Some(ns), None) => ns,
|
(Some(ns), None) => ns,
|
||||||
(None, None) => self.default_ns(),
|
(None, None) => self.default_ns(),
|
||||||
},
|
},
|
||||||
@ -145,7 +147,9 @@ impl<'xml> Context<'xml> {
|
|||||||
fn attribute_id(&self, attr: &Attribute<'xml>) -> Result<Id<'xml>, Error> {
|
fn attribute_id(&self, attr: &Attribute<'xml>) -> Result<Id<'xml>, Error> {
|
||||||
Ok(Id {
|
Ok(Id {
|
||||||
ns: match attr.prefix {
|
ns: match attr.prefix {
|
||||||
Some(ns) => self.lookup(ns).ok_or(Error::WrongNamespace)?,
|
Some(ns) => self
|
||||||
|
.lookup(ns)
|
||||||
|
.ok_or_else(|| Error::UnknownPrefix(ns.to_owned()))?,
|
||||||
None => self.default_ns(),
|
None => self.default_ns(),
|
||||||
},
|
},
|
||||||
name: attr.local,
|
name: attr.local,
|
||||||
|
@ -108,16 +108,14 @@ pub enum Error {
|
|||||||
MissingValue(&'static Kind<'static>),
|
MissingValue(&'static Kind<'static>),
|
||||||
#[error("unexpected token: {0}")]
|
#[error("unexpected token: {0}")]
|
||||||
UnexpectedToken(String),
|
UnexpectedToken(String),
|
||||||
#[error("missing prefix")]
|
#[error("unknown prefix: {0}")]
|
||||||
MissingdPrefix,
|
UnknownPrefix(String),
|
||||||
#[error("unexpected node: {0}")]
|
#[error("unexpected node: {0}")]
|
||||||
UnexpectedNode(String),
|
UnexpectedNode(String),
|
||||||
#[error("unexpected state: {0}")]
|
#[error("unexpected state: {0}")]
|
||||||
UnexpectedState(&'static str),
|
UnexpectedState(&'static str),
|
||||||
#[error("expected scalar")]
|
#[error("expected scalar")]
|
||||||
ExpectedScalar,
|
ExpectedScalar,
|
||||||
#[error("wrong namespace")]
|
|
||||||
WrongNamespace,
|
|
||||||
#[error("duplicate value")]
|
#[error("duplicate value")]
|
||||||
DuplicateValue,
|
DuplicateValue,
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ fn other_namespaces() {
|
|||||||
from_str(
|
from_str(
|
||||||
"<NestedOtherNamespace xmlns=\"URI\" xmlns:bar=\"BAZ\"><wrong:flag>true</wrong:flag></NestedOtherNamespace>"
|
"<NestedOtherNamespace xmlns=\"URI\" xmlns:bar=\"BAZ\"><wrong:flag>true</wrong:flag></NestedOtherNamespace>"
|
||||||
),
|
),
|
||||||
Err::<NestedOtherNamespace, _>(Error::WrongNamespace)
|
Err::<NestedOtherNamespace, _>(Error::UnknownPrefix("wrong".to_owned()))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Other namespace not-nested - wrong parser namespace
|
// Other namespace not-nested - wrong parser namespace
|
||||||
@ -153,6 +153,6 @@ fn other_namespaces() {
|
|||||||
from_str(
|
from_str(
|
||||||
"<StructOtherNamespace xmlns=\"URI\" xmlns:bar=\"BAZ\"><NestedOtherNamespace><wrong:flag>true</wrong:flag></NestedOtherNamespace></StructOtherNamespace>"
|
"<StructOtherNamespace xmlns=\"URI\" xmlns:bar=\"BAZ\"><NestedOtherNamespace><wrong:flag>true</wrong:flag></NestedOtherNamespace></StructOtherNamespace>"
|
||||||
),
|
),
|
||||||
Err::<StructOtherNamespace, _>(Error::WrongNamespace)
|
Err::<StructOtherNamespace, _>(Error::UnknownPrefix("wrong".to_owned()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user