diff --git a/Changelog.md b/Changelog.md index 666bcf85..9aecbb9e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -40,6 +40,7 @@ to get an offset of the error position. For `SyntaxError`s the range - [#684]: Fix incorrect position reported for `Error::IllFormed(DoubleHyphenInComment)`. - [#684]: Fix incorrect position reported for `Error::IllFormed(MissingDoctypeName)`. - [#704]: Fix empty tags with attributes not being expanded when `expand_empty_elements` is set to true. +- [#683]: Use local tag name when check tag name against possible names for field. ### Misc Changes @@ -72,6 +73,7 @@ to get an offset of the error position. For `SyntaxError`s the range [#629]: https://github.com/tafia/quick-xml/issues/629 [#675]: https://github.com/tafia/quick-xml/pull/675 [#677]: https://github.com/tafia/quick-xml/pull/677 +[#683]: https://github.com/tafia/quick-xml/issues/683 [#684]: https://github.com/tafia/quick-xml/pull/684 [#689]: https://github.com/tafia/quick-xml/pull/689 [#704]: https://github.com/tafia/quick-xml/pull/704 diff --git a/src/de/map.rs b/src/de/map.rs index 64ae6a68..3989a64d 100644 --- a/src/de/map.rs +++ b/src/de/map.rs @@ -789,7 +789,7 @@ fn not_in( start: &BytesStart, decoder: Decoder, ) -> Result { - let tag = decoder.decode(start.name().into_inner())?; + let tag = decoder.decode(start.local_name().into_inner())?; Ok(fields.iter().all(|&field| field != tag.as_ref())) } @@ -1181,6 +1181,8 @@ where #[test] fn test_not_in() { + use pretty_assertions::assert_eq; + let tag = BytesStart::new("tag"); assert_eq!(not_in(&[], &tag, Decoder::utf8()).unwrap(), true); @@ -1192,4 +1194,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 + ); } diff --git a/tests/serde-issues.rs b/tests/serde-issues.rs index a3e95b9e..2726e45a 100644 --- a/tests/serde-issues.rs +++ b/tests/serde-issues.rs @@ -462,3 +462,35 @@ fn issue580() { } ); } + +/// Regression test for https://github.com/tafia/quick-xml/issues/683. +#[test] +fn issue683() { + #[derive(Deserialize, Debug, PartialEq)] + enum ScheduleLocation { + #[serde(rename = "DT")] + Destination, + } + + #[derive(Deserialize, Debug, PartialEq)] + #[allow(non_snake_case)] + struct Schedule { + cancelReason: Option, + #[serde(rename = "$value")] + locations: Vec, + } + let xml = r#" + + + 918 + "#; + let result = quick_xml::de::from_str::(xml); + dbg!(&result); + assert_eq!( + result.unwrap(), + Schedule { + cancelReason: Some(918), + locations: vec![ScheduleLocation::Destination], + } + ); +}