Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

de: consider local name only for namespaced tags in structs with $value #736

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/de/key.rs
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> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move that function to de/mod.rs instead, so it will be available in all submodules.

let local = name.local_name();
Ok(decoder.decode(local.into_inner())?)
}
Expand Down
16 changes: 15 additions & 1 deletion src/de/map.rs
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 Expand Up @@ -1192,4 +1192,18 @@ fn test_not_in() {
not_in(&["some", "tag", "included"], &tag, Decoder::utf8()).unwrap(),
false
);

let tag_ns = BytesStart::new("ns1:tag");
assert_eq!(
not_in(&["no", "such", "tags"], &tag_ns, Decoder::utf8()).unwrap(),
true
);
assert_eq!(
not_in(&["some", "tag", "included"], &tag_ns, Decoder::utf8()).unwrap(),
false
);
assert_eq!(
not_in(&["some", "namespace", "ns1:tag"], &tag_ns, Decoder::utf8()).unwrap(),
true
);
}