Skip to content

overlapped-lists feature causes parser errors to xsi:nil fields after array fields #953

@weiznich

Description

@weiznich

We have a rather complex XML parser written with quick-xml that started failing some tests while trying to update from quick-xml 0.39.0 to 0.39.1. The old version did successful parse the document, the new version returned an error.

I minimized both the data and the code down to the following example:

pub mod bml {
    use super::*;

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct BoreholeType {
        #[serde(rename = "boreholeSegment")]
        pub borehole_segment: Vec<bml::BoreholeSegmentPropertyType>,
        #[serde(rename = "drillingProcess")]
        pub drilling_process: Option<Vec<DrillingProcess>>,
    }

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct BoreholeSegmentType {}

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct DrillingProcess {
        #[serde(rename = "DrillingProcess")]
        pub drilling_process: bml::DrillingProcessType,
    }

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct DrillingProcessType {
        #[serde(rename = "to")]
        pub to: gml::LengthType,
    }

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct BoreholeSegmentPropertyType {
        #[serde(rename = "BoreholeSegment")]
        pub borehole_segment: bml::BoreholeSegmentType,
    }
}

pub mod gml {

    #[derive(Debug, Clone, serde::Deserialize)]
    pub struct LengthType {
        #[serde(rename = "$value")]
        pub value: Option<f64>,
    }
}

fn main() {
    let input = r#"
<?xml version='1.0' encoding='UTF-8'?>
    <bml:Borehole xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/deprecatedTypes.xsd http://www.infogeo.de/boreholeml/3.0 https://www.infogeo.de/boreholeml/3.0/BoreholeML.xsd" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:bml="http://www.infogeo.de/boreholeml/3.0">
      <bml:boreholeSegment>
        <bml:BoreholeSegment>
          <bml:from>0.0</bml:from>
        </bml:BoreholeSegment>
      </bml:boreholeSegment>
      <bml:drillingProcess xsi:nil="true"/>
    </bml:Borehole>
"#;
    let res = quick_xml::de::from_str::<bml::BoreholeType>(&input);
    assert!(res.is_ok(), "Error: {}", res.unwrap_err());
}

With that I run git bisect against all revisions between the 0.39.0 and the 0.39.1 tag. This reported 210d3e1 as the first failing commit.

For me this looks like something around the parsing of xsi:nil="true" must have changed there as the parser now tries to parse inner fields of a null value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraysIssues related to mapping XML content onto arrays using serdebugserdeIssues related to mapping from Rust types to XML

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions