RReverser / serde-xml-rs

xml-rs based deserializer for Serde (compatible with 1.0+)
https://crates.io/crates/serde-xml-rs
MIT License
273 stars 92 forks source link

UnexpectedToken Error decoding xml that has a `<br />` tag in it (fetched from a jenkins config.xml) #215

Open merc1031 opened 3 months ago

merc1031 commented 3 months ago

I fetch a more complex config.xml from jenkins, and distilled it down to this test case.

simplified xml test_failing_description.xml

<?xml version="1.0" encoding="UTF-8"?><project>
    <description>
  <br/>
    Text
    </description>
</project>  

test

    #[rstest]
    fn test_failing_description() {
        #[derive(Debug, Deserialize)]
        #[serde(rename_all = "camelCase")]
        pub struct SimpleProject {
            pub description: String,
        }

        let d: PathBuf = [
            env!("CARGO_MANIFEST_DIR"),
            "test_resources",
            "jenkins",
            "xml",
            "job",
            "test_failing_description.xml",
        ]
        .iter()
        .collect();
        let xml = fs::read_to_string(d).expect("Unable to read file");
        let job: SimpleProject = serde_xml_rs::from_str(&xml).unwrap();
        println!("{:?}", job);
    }

error

    thread 'jenkins::xml::job::tests::test_failing_description' panicked at src/jenkins/xml/job.rs:766:63:
called `Result::unwrap()` on an `Err` value: UnexpectedToken { token: "XmlEvent::Characters(s)", found: "StartElement(br, {\"\": \"\", \"xml\": \"http://www.w3.org/XML/1998/namespace\", \"xmlns\": \"http://www.w3.org/2000/xmlns/\"})" }