Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/reader/ns_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::Deref;
use std::path::Path;

use crate::errors::Result;
use crate::events::{BytesText, Event};
use crate::events::{BytesStart, BytesText, Event};
use crate::name::{NamespaceResolver, QName, ResolveResult};
use crate::reader::{Config, Reader, Span, XmlSource};

Expand Down Expand Up @@ -91,6 +91,10 @@ impl<R> NsReader<R> {
Ok(Event::Empty(e))
}
Ok(Event::End(e)) => {
// push a fake element to the `ns_resolver` as the pending pop will remove it again
// if we don't push this element we don't increase the level, but the subsequent pending pop will
// decrease it anyway.
self.ns_resolver.push(&BytesStart::new(""))?;
Comment on lines 93 to +97

@Mingun Mingun Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only mask the issue in some cases. As described, the root cause lies in the event rewind code, that does not save/restore snapshots of NamespaceResolver state. The correct fix should implement such snapshoting.

// notify next `read_event_impl()` invocation that it needs to pop this
// namespace scope
self.pending_pop = true;
Expand Down
45 changes: 45 additions & 0 deletions tests/serde-de-xsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,48 @@ mod as_field {
}
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/953.
mod issue953 {
use super::*;

#[derive(Debug, Deserialize)]
struct BoreholeType {
#[serde(rename = "boreholeSegment")]
borehole_segment: Vec<()>,

#[serde(rename = "drillingProcess")]
drilling_process: Option<DrillingProcess>,
}

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

// success before 210d3e1d460a4c63e13d455b0b15623b77fa669c
// failed since 210d3e1d460a4c63e13d455b0b15623b77fa669c
#[test]
fn open_close() {
let input = r#"
<Borehole xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<boreholeSegment> </boreholeSegment>
<drillingProcess xsi:nil="true"/>
</Borehole>
"#;
let _: BoreholeType = from_str(&input).unwrap();
}

// failed always
#[test]
fn self_closed() {
let input = r#"
<Borehole xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<boreholeSegment/>
<drillingProcess xsi:nil="true"/>
</Borehole>
"#;
let _: BoreholeType = from_str(&input).unwrap();
}
}
Loading