Skip to content

Commit

Permalink
de: consider local_name only for namespaced tags in structs with $value
Browse files Browse the repository at this point in the history
This updates the "not_in" check that decides whether to pass a
new start tag within a struct to a $value field, to only consider
the local part of a QName. It now uses the same decode_name function
as the QNameDeserializer that is used for keys/fields already to
ensure they stay in sync.

Using the namespaced name in serde (i.e. `#[serde(rename = "ns1:tag")]`)
fails with ``Custom("missing field `ns1:tag`")`` today, so this will
not break existing code.

Might help with #347
  • Loading branch information
Xiphoseer committed Apr 12, 2024
1 parent 6e34a73 commit 6f7dda4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/de/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro_rules! deserialize_num {
/// The method will borrow if encoding is UTF-8 compatible and `name` contains
/// only UTF-8 compatible characters (usually only ASCII characters).
#[inline]
fn decode_name<'n>(name: QName<'n>, decoder: Decoder) -> Result<Cow<'n, str>, DeError> {
pub(super) fn decode_name<'n>(name: QName<'n>, decoder: Decoder) -> Result<Cow<'n, str>, DeError> {
let local = name.local_name();
Ok(decoder.decode(local.into_inner())?)
}
Expand Down
2 changes: 1 addition & 1 deletion src/de/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fn not_in(
start: &BytesStart,
decoder: Decoder,
) -> Result<bool, DeError> {
let tag = decoder.decode(start.name().into_inner())?;
let tag = super::key::decode_name(start.name(), decoder)?;

Ok(fields.iter().all(|&field| field != tag.as_ref()))
}
Expand Down

0 comments on commit 6f7dda4

Please sign in to comment.