Skip to content

Commit 5987bb4

Browse files
g-pichlerBergmann89
authored andcommitted
Fix a panic in interpreter when using multiple schemas without RESOLVE_INCLUDES
When processing multiple XSD schemas that share a common schema via `<xsd:import>`, `xsd-parser` 1.5.2 panics in the interpreter if `ParserFlags::RESOLVE_INCLUDES` is **not** set. The panic occurs in `crate_node_cache.rs:127` because the interpreter unconditionally calls `.unwrap()` on a `dependencies.get()` lookup. Without `RESOLVE_INCLUDES`, the `dependencies` map is empty, but the schema content still contains `<xsd:import>` elements with `schemaLocation` attributes. Fixed by gracefully skipping the unresolved imports when loading and falling back to global resolution.
1 parent 5166cfb commit 5987bb4

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

xsd-parser/src/pipeline/interpreter/state/crate_node_cache.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,28 @@ impl<'schema> NodeCacheProcessor<'_, 'schema> {
124124
schema_location: Some(schema_location),
125125
..
126126
}) => {
127-
let base = **info.dependencies.get(schema_location).unwrap();
128-
129-
self.process_schema(base)?;
127+
if let Some(base) = info.dependencies.get(schema_location) {
128+
self.process_schema(**base)?;
129+
}
130130
}
131131
C::Include(x) => {
132-
let base = **info.dependencies.get(&x.schema_location).unwrap();
133-
134-
self.process_schema(base)?;
132+
if let Some(base) = info.dependencies.get(&x.schema_location) {
133+
self.process_schema(**base)?;
134+
}
135135
}
136136
C::Override(x) => {
137-
let base = **info.dependencies.get(&x.schema_location).unwrap();
138-
139-
self.process_schema(base)?;
140-
self.process_override(x, base)?;
137+
if let Some(base) = info.dependencies.get(&x.schema_location) {
138+
let base = **base;
139+
self.process_schema(base)?;
140+
self.process_override(x, base)?;
141+
}
141142
}
142143
C::Redefine(x) => {
143-
let base = **info.dependencies.get(&x.schema_location).unwrap();
144-
145-
self.process_schema(base)?;
146-
self.process_redefine(x, base)?;
144+
if let Some(base) = info.dependencies.get(&x.schema_location) {
145+
let base = **base;
146+
self.process_schema(base)?;
147+
self.process_redefine(x, base)?;
148+
}
147149
}
148150
_ => (),
149151
}
@@ -927,7 +929,8 @@ impl<'schema> NodeCacheProcessor<'_, 'schema> {
927929

928930
let ident = self
929931
.ident_cache
930-
.resolve_for_schema(self.current_schema(), ident.clone())?;
932+
.resolve_for_schema(self.current_schema(), ident.clone())
933+
.or(self.ident_cache.resolve(ident))?;
931934

932935
Ok(ident)
933936
}

0 commit comments

Comments
 (0)