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

@@ -163,6 +163,17 @@ mod tests {
}
}
#[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() {
let schema_text = std::fs::read_to_string("../../action_schema.xsd").unwrap();

View File

@@ -23,8 +23,7 @@ impl ElementCloseStart {
element: Arc::clone(&self.element),
has_slash: true,
})]
} else {
if self.element.name.starts_with(c) {
} else if self.has_slash && self.element.name.starts_with(c) {
vec![Token::ElementCloseName(ElementCloseName::new(
Arc::clone(&self.element),
c.to_string(),
@@ -34,7 +33,6 @@ impl ElementCloseStart {
}
}
}
}
#[cfg(test)]
mod element_close_start_tests {