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

Attribute list parsing with serde does not treat \t as separator #674

Open
reknih opened this issue Oct 28, 2023 · 1 comment
Open

Attribute list parsing with serde does not treat \t as separator #674

reknih opened this issue Oct 28, 2023 · 1 comment
Labels
arrays Issues related to mapping XML content onto arrays using serde bug help wanted serde Issues related to mapping from Rust types to XML

Comments

@reknih
Copy link

reknih commented Oct 28, 2023

Deserialization of a list in an attribute value does not treat the tab character as a separator, despite the documentation stating that it should.

use quick_xml::de::Deserializer;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Any {
    #[serde(rename = "@list")]
    list: Vec<Item>,
}

#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "lowercase")]
enum Item {
    Foo,
    Bar,
}

#[test]
fn main() {
    // The separator between the two characters is a tab.
    let str = r#"<any list="foo	bar" />"#;
    let mut deser = Deserializer::from_str(str);
    let any = Any::deserialize(&mut deser).unwrap();
    assert_eq!(any.list, vec![Item::Foo, Item::Bar]);
}

Expected behavior: The assertion passes.
Actual behavior: thread 'main' panicked at 'called Result::unwrap() on an Err value: Custom("unknown variant foo\tbar, expected foo or bar")'

@Mingun Mingun added help wanted serde Issues related to mapping from Rust types to XML arrays Issues related to mapping XML content onto arrays using serde labels Oct 28, 2023
@Mingun
Copy link
Collaborator

Mingun commented Oct 28, 2023

This is because we do not normalize attribute values according to the specification yet, where all whitespace characters would be turned into space, but deserializer already written with that in mind.

@Mingun Mingun added the bug label Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays Issues related to mapping XML content onto arrays using serde bug help wanted serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants