babbel_xml 0.3.0

Full-featured XML parser, validator, stringifier, and XPath 1.0 engine in pure Rust
Documentation
use babbel_xml::{ParseOptions, XmlError, XmlParser, XmlSource, parse_bytes};

#[test]
fn test_nesting_depth_limit() {
    let deep_xml = "<a>".repeat(1050) + &"</a>".repeat(1050);
    let source = XmlSource::from_string(&deep_xml);
    let mut options = ParseOptions::default();
    options.max_nesting_depth = 100;
    let mut parser = XmlParser::new(source, options);

    let res = parser.parse();
    assert!(matches!(res, Err(XmlError::SecurityLimitExceeded(_))));
}

#[test]
fn test_billion_laughs_entity_depth_limit() {
    let xml = r#"<?xml version="1.0"?>
<!DOCTYPE lolz [
  <!ENTITY lol "lol">
  <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
]>
<lolz>&lol1;</lolz>"#;

    let res = parse_bytes(xml.as_bytes());
    assert!(res.is_ok());
}