Skip to content

Commit

Permalink
Merge pull request tafia#702 from leftmostcat/fix-namespaced-choices
Browse files Browse the repository at this point in the history
Consistently use local name when deserialize field name and when filter possible elements for `Vec` fields
  • Loading branch information
Mingun committed May 13, 2024
2 parents 2b2b773 + 6177189 commit 4a4abf7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 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 = decoder.decode(start.local_name().into_inner())?;

Ok(fields.iter().all(|&field| field != tag.as_ref()))
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
);
}
32 changes: 32 additions & 0 deletions tests/serde-issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
#[serde(rename = "$value")]
locations: Vec<ScheduleLocation>,
}
let xml = r#"
<schedule xmlns:ns2="http://www.thalesgroup.com/rtti/PushPort/Schedules/v3">
<ns2:DT/>
<ns2:cancelReason>918</ns2:cancelReason>
</schedule>"#;
let result = quick_xml::de::from_str::<Schedule>(xml);
dbg!(&result);
assert_eq!(
result.unwrap(),
Schedule {
cancelReason: Some(918),
locations: vec![ScheduleLocation::Destination],
}
);
}

0 comments on commit 4a4abf7

Please sign in to comment.