mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
xso-proc: fix renaming attributes using a static item
This was broken by d4d520e
by accident, and of course we didn't have
tests for that :-).
(we do, now)
This commit is contained in:
parent
9e07882531
commit
c0d109d9be
2 changed files with 27 additions and 24 deletions
|
@ -66,6 +66,13 @@ type Result = ((),);
|
||||||
|
|
||||||
static NS1: &str = "urn:example:ns1";
|
static NS1: &str = "urn:example:ns1";
|
||||||
|
|
||||||
|
static SOME_NAME: &::xso::exports::rxml::strings::NcNameStr = {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe {
|
||||||
|
::xso::exports::rxml::strings::NcNameStr::from_str_unchecked("bar")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||||
#[xml(namespace = NS1, name = "foo")]
|
#[xml(namespace = NS1, name = "foo")]
|
||||||
struct Empty;
|
struct Empty;
|
||||||
|
@ -149,13 +156,6 @@ fn empty_qname_check_has_precedence_over_attr_check() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SOME_NAME: &::xso::exports::rxml::strings::NcNameStr = {
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe {
|
|
||||||
::xso::exports::rxml::strings::NcNameStr::from_str_unchecked("bar")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||||
#[xml(namespace = NS1, name = SOME_NAME)]
|
#[xml(namespace = NS1, name = SOME_NAME)]
|
||||||
struct NamePath;
|
struct NamePath;
|
||||||
|
@ -234,6 +234,8 @@ fn required_attribute_missing() {
|
||||||
struct RenamedAttribute {
|
struct RenamedAttribute {
|
||||||
#[xml(attribute = "a1")]
|
#[xml(attribute = "a1")]
|
||||||
foo: String,
|
foo: String,
|
||||||
|
#[xml(attribute = SOME_NAME)]
|
||||||
|
bar: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -243,7 +245,7 @@ fn renamed_attribute_roundtrip() {
|
||||||
option::Option::{None, Some},
|
option::Option::{None, Some},
|
||||||
result::Result::{Err, Ok},
|
result::Result::{Err, Ok},
|
||||||
};
|
};
|
||||||
roundtrip_full::<RenamedAttribute>("<attr xmlns='urn:example:ns1' a1='bar'/>");
|
roundtrip_full::<RenamedAttribute>("<attr xmlns='urn:example:ns1' a1='bar' bar='baz'/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||||
|
|
|
@ -207,6 +207,12 @@ impl XmlCompoundMeta {
|
||||||
fn parse_prefixed_name(
|
fn parse_prefixed_name(
|
||||||
value: syn::parse::ParseStream<'_>,
|
value: syn::parse::ParseStream<'_>,
|
||||||
) -> Result<(Option<NamespaceRef>, NameRef)> {
|
) -> Result<(Option<NamespaceRef>, NameRef)> {
|
||||||
|
if !value.peek(LitStr) {
|
||||||
|
// if we don't have a string literal next, we delegate to the default
|
||||||
|
// `NameRef` parser.
|
||||||
|
return Ok((None, value.parse()?));
|
||||||
|
}
|
||||||
|
|
||||||
let name: LitStr = value.parse()?;
|
let name: LitStr = value.parse()?;
|
||||||
let name_span = name.span();
|
let name_span = name.span();
|
||||||
let (prefix, name) = match name
|
let (prefix, name) = match name
|
||||||
|
@ -284,9 +290,8 @@ impl XmlFieldMeta {
|
||||||
return Err(Error::new_spanned(meta.path, "duplicate `name` key"));
|
return Err(Error::new_spanned(meta.path, "duplicate `name` key"));
|
||||||
}
|
}
|
||||||
let value = meta.value()?;
|
let value = meta.value()?;
|
||||||
name = if value.peek(LitStr) {
|
|
||||||
let name_span = value.span();
|
let name_span = value.span();
|
||||||
let (new_namespace, name) = parse_prefixed_name(value)?;
|
let (new_namespace, new_name) = parse_prefixed_name(value)?;
|
||||||
if let Some(new_namespace) = new_namespace {
|
if let Some(new_namespace) = new_namespace {
|
||||||
if namespace.is_some() {
|
if namespace.is_some() {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
|
@ -296,11 +301,7 @@ impl XmlFieldMeta {
|
||||||
}
|
}
|
||||||
namespace = Some(new_namespace);
|
namespace = Some(new_namespace);
|
||||||
}
|
}
|
||||||
Some(name)
|
name = Some(new_name);
|
||||||
} else {
|
|
||||||
// just use the normal parser
|
|
||||||
Some(value.parse()?)
|
|
||||||
};
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else if meta.path.is_ident("namespace") {
|
} else if meta.path.is_ident("namespace") {
|
||||||
if namespace.is_some() {
|
if namespace.is_some() {
|
||||||
|
|
Loading…
Reference in a new issue