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

CDATA elements are not handled properly when deserializing $value #384

Closed
agausmann opened this issue May 6, 2022 · 4 comments
Closed
Labels
bug serde Issues related to mapping from Rust types to XML

Comments

@agausmann
Copy link

Put together an MCVE crate but I'll copy the relevant parts here:

I tried this code:

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Foo {
    #[serde(rename = "$value")]
    value: String,
}

fn main() {
    run_test("bad test case", b"<foo><![CDATA[<p>bar</p>]]></foo>");
    run_test("working test case", b"<foo>&lt;p&gt;bar&lt;/p&gt;</foo>");
}

fn run_test(name: &str, test_case: &[u8]) {
    let foo_result: Result<Foo, _> = quick_xml::de::from_reader(test_case);
    println!("{} as Foo: {:?}", name, foo_result);

    let string_result: Result<String, _> = quick_xml::de::from_reader(test_case);
    println!("{} as bare string: {:?}", name, string_result);

    println!();
}

and it produced this output:

bad test case as Foo: Err(Custom("missing field `$value`"))
bad test case as bare string: Ok("<p>bar</p>")

working test case as Foo: Ok(Foo { value: "<p>bar</p>" })
working test case as bare string: Ok("<p>bar</p>")

I expected to see:

bad test case as Foo: Ok(Foo { value: "<p>bar</p>" })
bad test case as bare string: Ok("<p>bar</p>")

working test case as Foo: Ok(Foo { value: "<p>bar</p>" })
working test case as bare string: Ok("<p>bar</p>")
@agausmann
Copy link
Author

This may be a duplicate of #186

@Mingun
Copy link
Collaborator

Mingun commented May 7, 2022

This bug is fixed by #374 which is merged in my fork https://github.com/Mingun/fast-xml. This project seems abandoned, so it's time to switch! I'll release 0.23 with this fix soon.

@agausmann
Copy link
Author

Thanks, I appreciate what you're doing! For the time being, I've moved away from serde-based XML deserializers, am currently trying out strong-xml, but it's good that someone is picking this back up.

@Mingun Mingun added bug serde Issues related to mapping from Rust types to XML labels May 21, 2022
@Mingun
Copy link
Collaborator

Mingun commented May 21, 2022

Because fast-xml merged back into quick-xml, this fix will be available in the next release which would be soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants