Skip to content

Exclude namespace from tag name when comparing against field names #702

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

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
}
);
}