Fix nested elements

This commit is contained in:
Niels Geens
2025-04-10 18:37:00 +02:00
parent 2f0fd21b0a
commit d81ae09f67
2 changed files with 17 additions and 8 deletions

View File

@@ -162,6 +162,17 @@ mod tests {
"Error should mention missing required attribute or invalid continuation");
}
}
#[test]
fn test_invalid_nesting() {
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();
let validator = XmlSchemaValidator::new(&schema_text).unwrap();
validator.clone().append("<reasoning><reasoning>").expect_err("Should fail because of nested tag");
validator.clone().append("<reasoning> <reasoning>").expect_err("Should fail because of nested tag, even with whitespace");
validator.clone().append("<reasoning>foo<reasoning>").expect_err("Should fail because of nested tag, even with text");
validator.clone().append("<reasoning> foo <reasoning>").expect_err("Should fail because of nested tag, even with text and whitespace");
validator.clone().append("<reasoning> foo <reasoning/>").expect_err("Should fail because of nested tag, even with self closing tag");
}
#[test]
fn test_stop_self_closing() {

View File

@@ -23,15 +23,13 @@ impl ElementCloseStart {
element: Arc::clone(&self.element),
has_slash: true,
})]
} else if self.has_slash && self.element.name.starts_with(c) {
vec![Token::ElementCloseName(ElementCloseName::new(
Arc::clone(&self.element),
c.to_string(),
))]
} else {
if self.element.name.starts_with(c) {
vec![Token::ElementCloseName(ElementCloseName::new(
Arc::clone(&self.element),
c.to_string(),
))]
} else {
vec![]
}
vec![]
}
}
}